你可以尝试这样的事情,打开新的 popup.aspx 页面,文件名作为查询参数。在新的弹出页面page_load中,读取内容并写入浏览器
<asp:GridView ID="FilterGrid" runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:TemplateField HeaderText="FileName" >
<ItemTemplate>
<asp:HyperLink ID="ActionHyperLink" runat="server" Text='<%# Eval("FileName") %>' NavigateUrl='<%# Eval("FileName","~/FilePopUp.aspx?filename={0}") %>' Target="_blank" />
<asp:HyperLink ID="HyperLink2" runat="server" Text='<%# Eval("FileName") %>' NavigateUrl='<%# String.Format("filepopup.aspx?filename={0}", Eval("filename")) %>' onclick="javascript:w= window.open(this.href,'DownloadFile','left=20,top=20,width=500,height=500,toolbar=0,resizable=0');return false;"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
弹出页面的加载量
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["filename"] != null)
{
//Get the content from database
byte[] fileContent = ....;
Response.Clear();
string doctype = ...;
if (doctype == ".doc")
{
Response.ContentType = "application/msword";
}
else if (doctype == ".pdf")
{
Response.ContentType = "application/pdf";
}
else if (doctype == ".xls")
{
Response.ContentType = "application/vnd.ms-excel";
}
else if (doctype == ".xlsx")
{
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
}
Response.BinaryWrite(fileContent);
}
}