Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Download link of the generated file changed when I moved the code to a new pop-up page [modified]

Download link of the generated file changed when I moved the code to a new pop-up page [modified]

Scheduled Pinned Locked Moved ASP.NET
helpjavascriptcomsysadminquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rafferty Uy
    wrote on last edited by
    #1

    Hi, this will be a bit tricky to explain but I'll try my best. Original page: I have a page with a button, which when clicked will generate a spreadsheet and prompt the user to download this spreadsheet. Changes: Now since we didn't want to the page to refresh, and at the same time we didn't want to implement an UpdatePanel to this page, we changed this button to a link which pops-up a new page. New page: The new page simply contains this button and a javascript link to close the window. I did not change the source code of the generate-spreadsheet method. Generate spreadsheet method:

    public static void Export(Page webPage)
    {
    webPage.Response.Clear();
    webPage.Response.Buffer = true;
    webPage.Response.Charset = "";
    webPage.EnableViewState = false;

    string filename = "spreadsheet.xls";
    webPage.Response.ContentType = "application/vnd.ms-excel";
    webPage.Response.ContentEncoding = Encoding.Default;
    webPage.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName + ";");
    
    string filePath = string.Format("{0}temp\\\\{1}", webPage.Request.PhysicalApplicationPath, fileName);
    populate(filePath);
    
    webPage.Response.TransmitFile(filePath);
    webPage.Response.Flush();
    File.Delete(filePath);
    
    webPage.Response.End();
    

    }

    Problem: Now here's my problem, the code works perfectly on my local machine, but does not work when I deployed on the server. On my local, it correctly gives me a download dialog with "spreadsheet.xls" displayed. On the server, it gives me a download dialog, but the URL (http://www.oursite.com/WebForms/WFrmExport.aspx) of the pop-up page is displayed instead. So when I click "Save", it will just give me an error. Additional notes: 1. The same export method is used in the original page and the new pop-up page 2. Both original pages and pop-up pages are webforms (*.aspx) 3. The original page works on the server... meaning it correctly prompts me to download "spreadsheet.xls". The problem only occurs on the pop-up page and only on the server. 4. If I remove the File.Delete(filePath); statement, I will see the generated spreadsheet.xls in the correct filepath server directory, which is the same directory used by the original page. What could be the problem?

    Rafferty

    modified on Friday, February 26, 2010 12:40 AM

    P R 2 Replies Last reply
    0
    • R Rafferty Uy

      Hi, this will be a bit tricky to explain but I'll try my best. Original page: I have a page with a button, which when clicked will generate a spreadsheet and prompt the user to download this spreadsheet. Changes: Now since we didn't want to the page to refresh, and at the same time we didn't want to implement an UpdatePanel to this page, we changed this button to a link which pops-up a new page. New page: The new page simply contains this button and a javascript link to close the window. I did not change the source code of the generate-spreadsheet method. Generate spreadsheet method:

      public static void Export(Page webPage)
      {
      webPage.Response.Clear();
      webPage.Response.Buffer = true;
      webPage.Response.Charset = "";
      webPage.EnableViewState = false;

      string filename = "spreadsheet.xls";
      webPage.Response.ContentType = "application/vnd.ms-excel";
      webPage.Response.ContentEncoding = Encoding.Default;
      webPage.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName + ";");
      
      string filePath = string.Format("{0}temp\\\\{1}", webPage.Request.PhysicalApplicationPath, fileName);
      populate(filePath);
      
      webPage.Response.TransmitFile(filePath);
      webPage.Response.Flush();
      File.Delete(filePath);
      
      webPage.Response.End();
      

      }

      Problem: Now here's my problem, the code works perfectly on my local machine, but does not work when I deployed on the server. On my local, it correctly gives me a download dialog with "spreadsheet.xls" displayed. On the server, it gives me a download dialog, but the URL (http://www.oursite.com/WebForms/WFrmExport.aspx) of the pop-up page is displayed instead. So when I click "Save", it will just give me an error. Additional notes: 1. The same export method is used in the original page and the new pop-up page 2. Both original pages and pop-up pages are webforms (*.aspx) 3. The original page works on the server... meaning it correctly prompts me to download "spreadsheet.xls". The problem only occurs on the pop-up page and only on the server. 4. If I remove the File.Delete(filePath); statement, I will see the generated spreadsheet.xls in the correct filepath server directory, which is the same directory used by the original page. What could be the problem?

      Rafferty

      modified on Friday, February 26, 2010 12:40 AM

      P Offline
      P Offline
      Pranay Rana
      wrote on last edited by
      #2

      I this it may be the issue of reading file form the server machine so you have to set account of the person who can access the local file system form server to do this : go to IIS Manager > right click on DefaultAppPool >> Go to poperties >> Go to Identity Tab >> set security account to local system

      R 1 Reply Last reply
      0
      • P Pranay Rana

        I this it may be the issue of reading file form the server machine so you have to set account of the person who can access the local file system form server to do this : go to IIS Manager > right click on DefaultAppPool >> Go to poperties >> Go to Identity Tab >> set security account to local system

        R Offline
        R Offline
        Rafferty Uy
        wrote on last edited by
        #3

        Hi, thanks for your reply. I don't think this is the problem because it can properly download the file if I revert back my changes in the server. The old code and the new changes both access from the same file location. this is a big headache

        Rafferty

        1 Reply Last reply
        0
        • R Rafferty Uy

          Hi, this will be a bit tricky to explain but I'll try my best. Original page: I have a page with a button, which when clicked will generate a spreadsheet and prompt the user to download this spreadsheet. Changes: Now since we didn't want to the page to refresh, and at the same time we didn't want to implement an UpdatePanel to this page, we changed this button to a link which pops-up a new page. New page: The new page simply contains this button and a javascript link to close the window. I did not change the source code of the generate-spreadsheet method. Generate spreadsheet method:

          public static void Export(Page webPage)
          {
          webPage.Response.Clear();
          webPage.Response.Buffer = true;
          webPage.Response.Charset = "";
          webPage.EnableViewState = false;

          string filename = "spreadsheet.xls";
          webPage.Response.ContentType = "application/vnd.ms-excel";
          webPage.Response.ContentEncoding = Encoding.Default;
          webPage.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName + ";");
          
          string filePath = string.Format("{0}temp\\\\{1}", webPage.Request.PhysicalApplicationPath, fileName);
          populate(filePath);
          
          webPage.Response.TransmitFile(filePath);
          webPage.Response.Flush();
          File.Delete(filePath);
          
          webPage.Response.End();
          

          }

          Problem: Now here's my problem, the code works perfectly on my local machine, but does not work when I deployed on the server. On my local, it correctly gives me a download dialog with "spreadsheet.xls" displayed. On the server, it gives me a download dialog, but the URL (http://www.oursite.com/WebForms/WFrmExport.aspx) of the pop-up page is displayed instead. So when I click "Save", it will just give me an error. Additional notes: 1. The same export method is used in the original page and the new pop-up page 2. Both original pages and pop-up pages are webforms (*.aspx) 3. The original page works on the server... meaning it correctly prompts me to download "spreadsheet.xls". The problem only occurs on the pop-up page and only on the server. 4. If I remove the File.Delete(filePath); statement, I will see the generated spreadsheet.xls in the correct filepath server directory, which is the same directory used by the original page. What could be the problem?

          Rafferty

          modified on Friday, February 26, 2010 12:40 AM

          R Offline
          R Offline
          Rafferty Uy
          wrote on last edited by
          #4

          I finally found the solution! I also had to clear the headers of the response, apparently, Response.Clear() only clears the content. Maybe the header was somehow populated incorrectly by the new pop-up page. So the fixed method is:

          public static void Export(Page webPage)
          {
          webPage.Response.ClearHeaders(); //added
          webPage.Response.Clear();
          webPage.Response.Buffer = true;
          webPage.Response.Charset = "";
          webPage.EnableViewState = false;

          string filename = "spreadsheet.xls";
          webPage.Response.ContentType = "application/vnd.ms-excel";
          webPage.Response.ContentEncoding = Encoding.Default;
          webPage.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName + ";");
          
          string filePath = string.Format("{0}temp\\\\{1}", webPage.Request.PhysicalApplicationPath, fileName);
          populate(filePath);
          
          webPage.Response.TransmitFile(filePath);
          webPage.Response.Flush();
          File.Delete(filePath);
          
          webPage.Response.End();
          

          }

          Thanks to all who wanted to help! :)

          Rafferty

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups