我們通過一個新的頁面VisioFile.ASPx來動態生成Visio文件,然後賦值給SRC屬性即可實現了。
VisioFile.ASPx的頁面只需要實現PageLoad函數即可,如下所示
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);
}
}
}
/// <summary>
/// 輸入Visio文件到流
/// </summary>
/// <param name="visioFile">Visio文件字節數組</param>
private void OutputVisioFile(byte[] visioFile)
{
Response.ContentType = "application/vnd.ms-visio.vIEwer";
Response.OutputStream.Write(visioFile, 0, visioFile.Length);
Response.Flush();
Response.End();
}
這樣我們就可以實現Web端展示Visio圖紙的功能了。