I am dynamically generating html file. It is formated with Css and Images. I am looking for code which should able to execute on button click, and ask the location for saving file. also it should download concern resource files which has referenced in html file. What code i have to do ? Can i use WebClient for the same ?
2 Answers
There is no "Save As" dialog in ASP.NET. Since it is running in a browser. You have no access to the user's file system, including the Save As dialog.
But you can send the user a file, as an attachment, most browsers will display a dialog asking the user whether to save the file or open it. Maybe the user will choose to save it.
Response.ContentType = "application/octet-stream" (or content type of your file).
Response.AppendHeader("content-disposition", "attachment;filename=" & strFileName)
You could create a situation where you can use WebClient if you make your file available through a uri, see this post.
1 Comment
Precious Roy
If you want it to download several files that are related in a particular manner, I would zip them and send one file
Yes, you can use WebClient. Option is to use HttpRequest and HttpResponse.
3 Comments
Red Swan
Thanks, But how i can download required resource folders with html file ? Can you please give me refernce any code lines ?
Abbas
If you know which files to get before the request for the HTML file, just call the Request/Response for every file. If it depends on the HTML file, you'll have to read the HTML file and get the reference to the external files and run another request with those files.
Red Swan
I think that's true. but how it is happens in browser itself ? in any browser if we saves page, it automatically get all referenced resource with it at saving location. how to implement this?