Microsoft Office 2013因Vb.net程序而崩溃
我有一个vb.net程序,用户可以从文本文件创建word文件,打开并编辑它,然后将更改保存回web服务器 当用户创建并上传文件时,一切正常。问题发生在他们打开任何文档时。当用户完成编辑并保存文件后,关闭word,Office抛出一条无响应消息并强制他们关闭Office程序,但当我检查他们试图上传到服务器的文档时,他们所做的更改已存在,因此我的程序正在无误地完成其过程,我认为 这仅在Microsoft Office 2013中发生 下面是我正在使用的代码:Microsoft Office 2013因Vb.net程序而崩溃,vb.net,ms-office,word-automation,Vb.net,Ms Office,Word Automation,我有一个vb.net程序,用户可以从文本文件创建word文件,打开并编辑它,然后将更改保存回web服务器 当用户创建并上传文件时,一切正常。问题发生在他们打开任何文档时。当用户完成编辑并保存文件后,关闭word,Office抛出一条无响应消息并强制他们关闭Office程序,但当我检查他们试图上传到服务器的文档时,他们所做的更改已存在,因此我的程序正在无误地完成其过程,我认为 这仅在Microsoft Office 2013中发生 下面是我正在使用的代码: Private Sub oWord_Do
Private Sub oWord_DocumentBeforeClose(ByVal Doc As Microsoft.Office.Interop.Word.Document, ByRef Cancel As Boolean) Handles oWord.DocumentBeforeClose
'Cancel = True
Try
oWord.ActiveDocument.Close()
Catch ex As Exception
MsgBox("There was an issue closing word document" & ex.ToString())
End Try
'oWord.Quit()
Try
oWord.Application.Quit()
Catch ex As Exception
MsgBox("There was an issue closing word" & ex.ToString())
End Try
Try
Dim filepath As String
'Dim url As String = Server & "php/PD026U.php"
Dim url As String = Server & LibName & "/PD026U.pgm"
'Dim url As String = "http://192.168.95.1:83/file.php"
filepath = strCommonAppData & IO.Path.GetFileName(ORGDoc)
Dim request As HttpWebRequest = DirectCast(HttpWebRequest.Create(url), HttpWebRequest)
request.PreAuthenticate = True
request.AllowWriteStreamBuffering = True
request.KeepAlive = True
request.ProtocolVersion = HttpVersion.Version10
Dim boundary As String = System.Guid.NewGuid().ToString()
request.Accept = "text/html , application/xhtml+xml, */*"
request.AutomaticDecompression = DecompressionMethods.GZip
request.ContentType = String.Format("multipart/form-data; boundary={0}", boundary)
request.Method = "POST"
request.Credentials = New System.Net.NetworkCredential("ehavermale", "ernie1")
' Build Contents for Post
Dim header As String = String.Format("--{0}", boundary)
Dim footer As String = header & "--"
Dim contents As New System.Text.StringBuilder()
Dim FileHead As New System.Text.StringBuilder()
' file
FileHead.AppendLine(header)
FileHead.AppendLine(String.Format("Content-Disposition: form-data; name=""upfile""; filename=""{0}""", IO.Path.GetFileName(filepath)))
FileHead.AppendLine("Content-Type: application/msword")
FileHead.AppendLine()
contents.AppendLine(vbCrLf & header)
contents.AppendLine("Content-Disposition: form-data; name=""task""")
contents.AppendLine()
contents.AppendLine("upload")
contents.AppendLine(header)
contents.AppendLine("Content-Disposition: form-data; name=""INCOMP""")
contents.AppendLine()
contents.AppendLine(INCOMP)
contents.AppendLine(header)
contents.AppendLine("Content-Disposition: form-data; name=""ProgLib""")
contents.AppendLine()
contents.AppendLine(LibName)
contents.AppendLine(header)
contents.AppendLine("Content-Disposition: form-data; name=""INCNUM""")
contents.AppendLine()
contents.AppendLine(INNUM)
contents.AppendLine(header)
contents.AppendLine("Content-Disposition: form-data; name=""ToPath""")
contents.AppendLine()
contents.AppendLine(ToPath)
' Footer
contents.AppendLine(footer)
' This is sent to the Post
Dim bytes As Byte() = System.Text.Encoding.UTF8.GetBytes(contents.ToString())
Dim FileBytes As Byte() = System.Text.Encoding.UTF8.GetBytes(FileHead.ToString())
request.ContentLength = bytes.Length + FileHead.Length + New FileInfo(filepath).Length
Using requestStream As Stream = request.GetRequestStream()
requestStream.Write(FileBytes, 0, FileBytes.Length)
Using fileStream As New IO.FileStream(filepath, IO.FileMode.Open, IO.FileAccess.Read)
Dim buffer(4096) As Byte
Dim bytesRead As Int32 = fileStream.Read(buffer, 0, buffer.Length)
Do While (bytesRead > 0)
requestStream.Write(buffer, 0, bytesRead)
bytesRead = fileStream.Read(buffer, 0, buffer.Length)
Loop
fileStream.Close()
End Using
requestStream.Write(bytes, 0, bytes.Length)
requestStream.Flush()
requestStream.Close()
Using response As WebResponse = request.GetResponse()
Using reader As New StreamReader(response.GetResponseStream())
Dim strResponseData As String = reader.ReadToEnd()
TextBox1.Text = strResponseData
End Using
End Using
End Using
Catch ex As Exception
MsgBox("There was an Error on File Upload Please Contact you Administrator for assistance : " & ex.ToString())
End Try
Me.Close()
End Sub
我尝试过改变我关闭word程序的方式,关闭文档和word的顺序,并试图保持word完全打开,但我尝试过的都不起作用
Office 2013在关闭或以编程方式关闭文档之前是否存在问题?我发现了问题。有一个名为Send to Bluetooth的COM加载项需要禁用,现在一切正常异常消息或堆栈跟踪是什么?它没有返回异常消息或堆栈跟踪。我检查了电脑上的应用程序日志,那里也没有错误。我得到的唯一信息是微软已经停止响应。然后我完成了解决过程,最后告诉我没有发现任何问题,并关闭程序。程序何时崩溃?在哪一行?我不知道。我的程序正在按它应该的方式执行(即,用户保存他们正在处理的文件,然后我将该文件发送到我们的服务器。该文件将毫无错误地发送到我们的服务器)我找到了破坏文字的行,它是oWord.ActiveDocument.Close(),但我需要关闭该文档才能将其上载到我们的服务器。是否有其他方法可以关闭Office 2013可以处理的文档?