By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,203 Members | 1,646 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,203 IT Pros & Developers. It's quick & easy.

"save file" dialog box in clients

P: 31
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
May 23 '08 #1
Share this Question
Share on Google+
3 Replies


Plater
Expert 5K+
P: 7,872
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
Expand|Select|Wrap|Line Numbers
  1. Response.Clear();
  2. Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
  3. Response.ContentType = ContentTypeString;
  4. Response.AddHeader("content-disposition", "attachment; filename=" + FileName);
  5. Response.WriteFile(FullPathFileName);
  6. Response.End();
  7.  
May 23 '08 #2

Curtis Rutland
Expert 2.5K+
P: 3,256
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.

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
May 23 '08 #3

Frinavale
Expert Mod 5K+
P: 9,731
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
May 23 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.