我有一个vb.net程序,用户可以从文本文件创建一个word文件,打开并编辑它,并将其更改保存回Web服务器。
当用户创建文件并上传时,一切正常。当他们打开任何文档时会发生问题。当用户完成编辑并保存文件然后关闭单词时,Office会抛出一条无响应的消息并强制他们关闭办公室程序,但当我检查他们尝试上传到服务器的文档时,他们所做的更改是存在的,所以我认为我的程序正在完成其过程而没有错误。
这仅在Microsoft Office 2013中发生。
以下是我正在使用的代码:
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
我已经尝试改变我关闭单词程序的方式,关闭文档和单词的顺序,并尝试完全打开单词,我尝试过的任何工作都没有。
Office 2013是否存在问题,是否已关闭或以编程方式关闭文档?
答案 0 :(得分:0)
我发现了我的问题。有一个名为Send to Bluetooth的COM加载项需要被禁用,现在一切正常