导出到Excel时显示等待图像

时间:2013-11-15 11:24:07

标签: c# asp.net excel

 <asp:ScriptManager ID="ScriptManager1" runat="server"/>
 <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<asp:Image ID="Image1" ImageUrl="waiting.gif" AlternateText="Processing" runat="server" />
</ProgressTemplate>
</asp:UpdateProgress>
 <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
 <ContentTemplate>
 <asp:ImageButton ID="imgBtn_PDF" runat="server" ImageUrl="../images/pdf.png" Width="34" Height="17" Style="padding-top: 7px"  OnClick="imgBtn_PDF_Click"   />
  </ContentTemplate>
  <Triggers>
 <asp:PostBackTrigger ControlID="imgBtn_PDF" />
 </Triggers>
 </asp:UpdatePanel>  

In the above code am using the update panel i am displaying waiting message with progress bar while exporting to PDF.The image is displayed when i use the trigger as asynchronous postback but am not able to export to PDF.But when use postbacktrigger am not able to display the waiting message.Below is my codebehind code to export to excel  

Response.ContentType = "application/pdf";
                Response.AddHeader("content-disposition", "attachment; filename=" + Path.GetFileName(pdfFile));
                sourceFile = new FileStream(pdfFile, FileMode.Open);
                long FileSize;
                FileSize = sourceFile.Length;
                byte[] getContent = new byte[(int)FileSize];
                sourceFile.Read(getContent, 0, (int)sourceFile.Length);
                sourceFile.Close();
                Response.BinaryWrite(getContent);

在上面的代码中,我添加了一个PDF类型的标题,在打开模式下打开文件并将内容存储在字节的getContent中,然后通过字节读取整个文件并导出throgh BinaryWrite

0 个答案:

没有答案