0

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 2

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

If you want it to download several files that are related in a particular manner, I would zip them and send one file
1

Yes, you can use WebClient. Option is to use HttpRequest and HttpResponse.

3 Comments

Thanks, But how i can download required resource folders with html file ? Can you please give me refernce any code lines ?
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.
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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.