Asanka
Asanka

Reputation: 559

Downloading a file from server and save it in client

I am currently developing an ASP.net application, where I generate a word document in server and I want to save it in client machine who access that feature with out user interactions. How can I download it and save it in client machine, using Javascript?

Upvotes: 4

Views: 13937

Answers (3)

Ramiz Uddin
Ramiz Uddin

Reputation: 4259

Use System.Net.WebClient.DownloadFile and you are doing bulk downloads then do use WebClient.DownloadProgressChanged Event. Sometimes we do bulk download but user get the impression that system stuck or fail somewhere and start hitting refresh. Avoid that!

Upvotes: 1

Pratik
Pratik

Reputation: 11745

You can do either of this :

CASE 1 :

private static string GetWebTest1(string url)        
{            
     System.Net.WebClient Client = new WebClient();            
     return Client.DownloadString(url);        
}

CASE 2 :

 private static string GetWebTest2(string url)        
 {            
      HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
      WebResponse response = request.GetResponse();
      Stream stream = response.GetResponseStream();            
      StreamReader reader = new StreamReader(stream);            
      return reader.ReadToEnd();        
 }

Upvotes: 1

anishMarokey
anishMarokey

Reputation: 11397

you cann't save it in clients machine with out knowledge of client.

You can give a link of the word document,user need to click on the link and save it in his machine.

 <a href="serverLink.doc" >Click to Save Word document</a>

Note: you cant do any manipulation on client PC by using Javascript or any scripting language

Upvotes: 3

Related Questions