WebBrowser当打开过doc或docx文件后,再次打开别的文件会提示未将对象引用设置到对象的实例。附件提取失败,可能并不存在附件!
麻烦老师指导下,怎么避免这个错误呢?
依次弹出如下两个提示:
---------------------------
提示
---------------------------
未将对象引用设置到对象的实例。
---------------------------
确定
---------------------------
---------------------------
提示
---------------------------
附件提取失败,可能并不存在附件!
---------------------------
确定
---------------------------
确定后,后续打开的doc文件就不显示了 web控件直接是空白
如果打开doc文件 然后打开其他非doc文件之后 在打开doc文件 又偶尔不会出现上述错误提示……
代码如下:
Dim zs1 As Integer = Tables(e.form.name & "_table2").Count
If zs1 >0 Then
Dim wb As WinForm.WebBrowser = e.Form.Controls("WebBrowser1")
Dim tb As WinForm.TabControl = e.Form.Controls("TabControl1")
Dim pc As WinForm.PictureBox = e.Form.Controls("PictureBox1")
Dim lst As List(of String)
lst = Tables(e.form.name & "_table2").Current.DataRow.Lines("文件名")
'msgbox("第一个文件为:" & lst(0))
vars("文件名")=lst(0)
Dim dr As DataRow = Tables(e.form.name & "_table2").Current.DataRow
Dim fl As String = ProjectPath & "下载文件\" & lst(0)
If Tables(e.form.name & "_table2").Current Is Nothing Then
wb.Address=Nothing
pc.Image = GetImage(Nothing)
Return
End If
If FileSys.FileExists(fl) AndAlso CRCCheckFile(fl) = dr.SQLGetValue("CRC值") Then '如果本地存在同名文件且CRC校验值相同
'则直接使用本地文件
Else '否则从数据库提取文件
If dr.SQLLoadFile("附件",fl) = False Then '如果提取文件失败
Messagebox.Show("附件提取失败,可能并不存在附件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
Return
End If
End If
Dim bbb As String =dr("文件类型")
If bbb.Contains("bmp") Or bbb.Contains("jpg") Or bbb.Contains("gif") Or bbb.Contains("png") Then
wb.Address = Nothing
pc.Image = GetImage(fl)
tb.SelectedIndex=1
Else If bbb.Contains("xls") Or bbb.Contains("xlsx") Or bbb.Contains("doc") Or bbb.Contains("docx") Or bbb.Contains("txt") Or bbb.Contains("pdf") Then
wb.Address = fl
wb.OfficeToolBar = True
pc.Image = GetImage(Nothing)
tb.SelectedIndex=0
End If
vars("文件")=fl
If Forms("全屏预览").opened Then
Dim bt As WinForm.Button = Forms("全屏预览").Controls("Button1")
bt.PerformClick
End If
End If
[此贴子已经被作者于2022/5/26 11:30:33编辑过]