vb.net如何利用axwebbrowser控件显示保存在SQL image字段中的word文件?

哥是龙王 2019-11-14 09:27:57
想利用axwebbrowser控件显示保存在SQL image字段中的word文件,我目前是采用把image字段取出后保存在本地形成word文件,再用axbrowser打开,但是如果连续两次运行下面这个代码,系统会提示word文件正在被使用,想请教一下,能否利用axbrowser控件直接读取内存中的文件流而无需转存在本地再调用?

 
If Not tmp.StartsWith("ok") Then
If ZYT_Connection.State = ConnectionState.Closed Then ZYT_Connection.Open()
Dim SqlInfoNR1 As New SqlCommand("select INFO_NR1 from info where info_id='" & TreeView_ML.SelectedNode.Tag & "'", ZYT_Connection)
Dim mFILENAME As String = TreeView_ML.SelectedNode.Tag & ".doc"
Dim ByteArr() As Byte
ByteArr = SqlInfoNR1.ExecuteScalar

Try
If (ByteArr.Length > 0) Then
Dim fs As FileStream = New FileStream(mFILENAME, FileMode.OpenOrCreate)
Dim w As New BinaryWriter(fs)
w.Write(ByteArr)
w.Flush()
w.Close()
fs.Close()
Dim temp_path As New FileInfo(mFILENAME)
AxWebBrowser1.Navigate("about:blank")
AxWebBrowser1.Navigate(temp_path.DirectoryName & "\" & temp_path.Name)
Else

End If
Catch ex As Exception
MessageBox.Show("系统出错:" & Chr(13) & ex.Message, "转写本地文件出错提示", MessageBoxButtons.OK, MessageBoxIcon.Error)

Finally
If ZYT_Connection.State = ConnectionState.Open Then ZYT_Connection.Close()
End Try

Else
TextBox1.Text = TreeView_ML.SelectedNode.Text
' bt_tq01.PerformClick()
End If
...全文
93 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
jhonsonzhang 2019-11-23
  • 打赏
  • 举报
回复
调用前kill所有word进程,这样应该不需二次调用。 但建议抛弃AX,根据业务逻辑,看看能否进行调整,后期编辑直接抛给word了,自身程序不用带个AX去调用。

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧