-2

Is there any way to trigger "Save as" dialog box in asp.net. I know it is not possible in Java Script to control client's machine. Is there any way to trigger the dialog box on Click of a dowload button. The scenario is I generate a XML, which must be downloaded on client's machine. The "Save as " dialog box should pop up on the button click. Thanks in Advance.

Nithin
  • 3
  • 5
  • 1
    How much research did you do on your own? I've googled for less than one 1 min and found https://stackoverflow.com/questions/5027632/jquery-file-save-as-dialog-box – Carsten Løvbo Andersen Nov 02 '17 at 06:54
  • 3
    Possible duplicate of [jquery file save as dialog box](https://stackoverflow.com/questions/5027632/jquery-file-save-as-dialog-box) – Carsten Løvbo Andersen Nov 02 '17 at 06:54
  • I don't want to download the web page. I need to download the XML which gets generated in the Web Page Itself in the client's hard drive. Thanks. If that is possible in Javascript, then there occurs security issues. – Nithin Nov 02 '17 at 07:14
  • This will help https://stackoverflow.com/questions/2897619/using-html5-javascript-to-generate-and-save-a-file – Sarvesh Mishra Nov 02 '17 at 08:35
  • Possible duplicate of [Using HTML5/Javascript to generate and save a file](https://stackoverflow.com/questions/2897619/using-html5-javascript-to-generate-and-save-a-file) – Sarvesh Mishra Nov 02 '17 at 08:36

1 Answers1

1

try this

String FileName = "FileName.txt";
String FilePath = "C:/...."; //Replace this
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.ClearContent();
response.Clear();
response.ContentType = "text/plain";
response.AddHeader("Content-Disposition", "attachment; filename=" + FileName 
+ ";");
response.TransmitFile(FilePath);
response.Flush();
response.End();
Lior
  • 508
  • 3
  • 18
  • 1
    Thanks , but I've tried this code already. This helps in picking up the file and download it in the default folder of the browser and does not trigger "Save as " dialog box. – Nithin Nov 02 '17 at 08:36