Downloading a file from the server and saving it in the client

I am currently developing an ASP.net application where I create a text document on a server and I want to save it on a client computer that gains access to this function without user interaction. How to download it and save it on the client machine using Javascript?

+3
source share
3 answers

you cannot save it in a client machine without customer knowledge.

You can give the linkdocument words, the user needs to click on the link and save it on his computer.

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

Note: you cannot do any manipulations on the client PC using Javascript or any scripting language

+3

:

1:

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

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();        
 }
+1

Use System.Net.WebClient.DownloadFileand you do bulk uploads, then use WebClient.DownloadProgressChangedEvent . Sometimes we load a bulk download, but the user gets the impression that the system is stuck or something worked somewhere and starts to beat refresh. Avoid this!

+1
source

Source: https://habr.com/ru/post/1774905/


All Articles