資料庫儲存二進位 Visio 檔案,Web 端透過專用頁面 VisioFile.aspx 讀取並輸出串流,供 Visio Viewer ActiveX 控制項載入。
private void Page_Load(object sender, System.EventArgs e)
{
string VisioID = Request.QueryString["VisioID"];
if (VisioID != null)
{
VisioImageRelease VisioImage = new VisioImageRelease();
using (IDataReader dr = VisioImage.GetByVisioID(VisioID))
{
dr.Read();
byte[] visioImage = (byte[])dr["visioImage"];
OutputVisioFile(visioImage);
}
}
}
private void OutputVisioFile(byte[] visioFile)
{
Response.ContentType = "application/vnd.ms-visio.viewer";
Response.OutputStream.Write(visioFile, 0, visioFile.Length);
Response.Flush();
Response.End();
}
application/vnd.ms-visio.viewer 觸發 Visio Viewer ActiveX 載入Response.OutputStream.Write 避免文字編碼損壞Response.End() 防止後續 HTML 污染串流VisioID 關聯資料庫記錄using 確保 IDataReader 正確關閉VisioContainer.aspx 載入 Viewer ActiveXViewer1.src = 'VisioFile.aspx?VisioID=xxx'VisioFile.aspx 讀取資料庫 → 輸出二進位串流