Click here to Skip to main content
13,453,437 members (47,158 online)
Rate this:
Please Sign up or sign in to vote.
See more:
At a high-level this does not seem like rocket science, but it is proving to be a challenge. I am more familiar with c# windows form development. I am now creating a webpage and need to incorporate the equivalent of windows form SaveFileDialog functionality into the webpage. At the very least, I need to give the end user the ability to select their own file path and name for which data from a GridView will be saved. What are my options?
Posted 29-Sep-12 4:38am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I guess you want something like this:
FileStream sourceFile = new FileStream(Server.MapPath(@"FileName"), FileMode.Open); 
float FileSize; 
FileSize = sourceFile.Length; 
byte[] fileContent = new byte[(int)FileSize]; 
sourceFile.Read(fileContent, 0, (int)sourceFile.Length); 
Response.Buffer = true; 
Response.ContentType = "application/octet-stream"; 
Response.AddHeader("Content-Length", fileContent.Length.ToString()); 
Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName); 

Best regards
Espen Harlinn
meganh40 29-Sep-12 11:06am
How do I ask the user what their mapped path is and allow them the ability to browse their directory structure?
Espen Harlinn 29-Sep-12 11:15am
I assumed you wanted return a file from your web application, which executes on the server. If this is the case, then Server.MapPath is relative to your web application on the server. The above code enables you to send a file from your server side web application to the browser, which will open a "save as" dialog for the returned file.
meganh40 29-Sep-12 11:34am
Thanks so much. This worked perfectly!
Espen Harlinn 29-Sep-12 11:34am
Brilliant :-D
ridoy 29-Sep-12 13:43pm
Espen Harlinn 29-Sep-12 13:44pm
Thank you, ridoy :-D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.180318.3 | Last Updated 29 Sep 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100