想利用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
uj5u.com熱心網友回復:
呼叫前kill所有word行程,這樣應該不需二次呼叫。但建議拋棄AX,根據業務邏輯,看看能否進行調整,后期編輯直接拋給word了,自身程式不用帶個AX去呼叫。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/94821.html
標籤:VB.NET
上一篇:c#表單計算器保存的 運算程序
下一篇:VS中,出現問題,該怎么解決?
