DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Tue, 31 Jul 2007 16:14:19 -0600,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    Michael D. Ober obermd.@.alum.mit.edu.nospam


ASP.NET 2.0/C# Response to client is masterpage instead of file.   
When I single step through the code below, it sends back the PDF file that 
is retrieved in the line fm.GetAccountPDF(...).  When I run without single 
stepping, I get the master page for this page.  I have actually saved the 
file returned by IE 7 as a text file and opened it in notepad, so I have 
confirmed that it is indeed the page master being returned.  The code is in 
the code behind file for the aspx page and is called directly from a link on 
the page.  In all cases, the PDF file is correctly created on the server and 
I can open it directly from Windows Explorer.  This code is actually 
slightly modified from the code in MS TechNet article 812406 
http://support.microsoft.com/kb/812406/en-us.

What am I doing wrong?

Thanks,
Mike Ober.


protected void StreamFile(object sender, EventArgs e)
{
  const int ChunkSize = 8192; // Use a cluster size multiple for performance
  FileManager fm = null;
  System.IO.Stream iStream = null;
  try {
    fm = new FileManager((ASPNET2VAX.Core)Session["vax"]);
    try {
      System.IO.FileInfo fiPDF = 
fm.GetAccountPDF(Request.QueryString["id"]);
      // Total bytes to read:
      long dataToRead = fiPDF.Length;
      Response.Clear();
      Response.AppendHeader("Content-Disposition", "attachment; filename=" + 
fiPDF.Name);
      Response.AppendHeader("Content-Length", dataToRead.ToString());
      Response.ContentType = 
ASPNET2VAX.SupportRoutines.LookupMIMEType(fiPDF);
      // Now write the file
      // Buffer to read sytes in chunks:
      byte[] buffer;
      // Length of the file:
      int length;
      // Open the file.
      iStream = new System.IO.FileStream(fiPDF.FullName,
                                                               System.IO.FileMode.Open,
                                                               System.IO.FileAccess.Read,
                                                               System.IO.FileShare.Read);
      // Read the bytes.
      while (dataToRead > 0) {
        // Verify that the client is connected.
        if (Response.IsClientConnected) {
          // Read the data in buffer.
          buffer = new byte[ChunkSize];
          length = iStream.Read(buffer, 0, ChunkSize);
          // Write the data to the current output stream.
          Response.OutputStream.Write(buffer, 0, length);
          // Flush the data to the HTML output.
          Response.Flush();
          // Update our position
          dataToRead = dataToRead - length;
        } else {
          //prevent infinite loop if user disconnects
          dataToRead = -1;
        }
      }
      Response.End();

    } catch (Exception ex) {
      hgc_outputMsg.InnerHtml += ex.Message;

    } finally {
      if (iStream != null) {
        iStream.Close();
      }
    }

  } catch {
    Response.Redirect(SingularityLibrary.config.CoreConfiguration.appPath(Request).ToString() 
+ "/" + Wakefield.Core.Config.WakefieldConfig.ClientLoginPage);
  }
}
Date:Tue, 31 Jul 2007 16:14:19 -0600   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us