"save file" dialog box in clients

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anudu
    New Member
    • Oct 2007
    • 31

    "save file" dialog box in clients

    hi,

    I am developing a system with asp.net, c#, and ajax.

    I have an excel file in server in "Server.MapPath ("ExcelFiles/Test.xls")".

    I want to make it available to save to the disk in client side. I hope save file dialoge box will allow to do this. How can i do this?

    thanks

    Anushka
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Provide a link to the file? Or at least a page that will serve it up.
    You will also need to remember add the content-disposition header to get the save file box to pop up in your clients browser.

    Heres part of something I use
    Code:
    Response.Clear();
    Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
    Response.ContentType = ContentTypeString;
    Response.AddHeader("content-disposition", "attachment; filename=" + FileName);
    Response.WriteFile(FullPathFileName);
    Response.End();

    Comment

    • Curtis Rutland
      Recognized Expert Specialist
      • Apr 2008
      • 3264

      #3
      Your best bet is to present the file for download. You could redirect to a page with a link to the download. But I am pretty sure that you can't use a Save File dialogue, because you can't create client side popups with server side code. But if you present it as a download, the client will get the browser's save file dialog.

      Originally posted by anudu
      hi,

      I am developing a system with asp.net, c#, and ajax.

      I have an excel file in server in "Server.MapPath ("ExcelFiles/Test.xls")".

      I want to make it available to save to the disk in client side. I hope save file dialoge box will allow to do this. How can i do this?

      thanks

      Anushka

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Originally posted by insertAlias
        Your best bet is to present the file for download. You could redirect to a page with a link to the download. But I am pretty sure that you can't use a Save File dialogue, because you can't create client side popups with server side code. But if you present it as a download, the client will get the browser's save file dialog.
        InsertAlias is correct, you cannot call the "SaveAs" dialog box in ASP.NET.
        However you can just use an old-fashioned hyperlink that points to the file. Since Excel files can't be rendered in the browser, the browser itself will open a "SaveAs" dialog box to allow the user to download the file.

        Make sure that the folder that contains the Excel file is on the web server or else this will not work.

        -Frinny

        Comment

        Working...