Я открываю документ Word и сохраняю его в формате html со следующим кодом.Если я устанавливаю objWord.Visible = False, я получаю ошибку: Исключение из HRESULT: 0x800A1098, которое, как я считаю, указывает, что открывать нечего.Если я установил objWord.Visible = True, код выполняется правильно, но я не хочу, чтобы конечный пользователь видел слово в действии.Буду признателен за любую помощь.
заранее спасибо
Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim objWord As Microsoft.Office.Interop.Word.ApplicationClass = New ApplicationClass()
If Not (fUpload.HasFile) Then
lblMessage.Text = "Please choose file to upload"
Else
Try
Dim strFileName As String = fUpload.FileName
Dim strSep As String() = fUpload.FileName.Split("."c)
Dim arrLength As Integer = strSep.Length - 1
Dim strExt As String = strSep(arrLength).ToString().ToUpper()
'Save the uploaded file to the folder
strPathToUpload = Server.MapPath("Uploaded")
strPathToConvert = Server.MapPath("WordToHtml")
Dim FileName As Object = (strPathToUpload & "\") + fUpload.FileName
Dim FileToSave As Object = (strPathToConvert & "\") + Left(fUpload.FileName, Len(fUpload.FileName) - 4) & ".htm"
If strExt.ToUpper().Equals("DOC") Then
fUpload.SaveAs((strPathToUpload & "\") + fUpload.FileName)
lblMessage.Text = "File uploaded successfully"
'open file in word
objWord.Documents.Open(FileName, missing, [readOnly], missing, missing, missing, missing, missing, missing, missing, missing, isVisible)
objWord.Visible = False 'error occures here if False
Dim oDoc As Microsoft.Office.Interop.Word.Document = objWord.ActiveDocument
If oDoc.Application.Version = "12.0" Then ' Word 2007 version
oDoc.SaveAs2(FileToSave, fltDocFormat, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing)
Else ' word 2003 version
oDoc.SaveAs(FileToSave, fltDocFormat, missing, missing, missing, missing, missing, missing, missing, missing, missing)
End If
Else
lblMessage.Text = "Invalid file selected!"
End If
'Close/quit word
objWord.Quit(missing, missing, missing)
Catch ex As Exception
objWord.Quit(missing, missing, missing)
Response.Write(ex.Message)
End Try
End If
End Sub