Front-end code:<a href="/test/getfilepath"> Background code: Public Class test{publicstring GetFilePath () {return' http://192.168.0.1//upload//file 1.doc " ;}}
If this a tag directly assigns the file address to the HREF, some files are opened directly instead of downloaded, for example:. txt,.pdf format;
So I changed the backend back string to return as a stream, as in the following example:
PublicActionResult GetFilePath (stringa_id) { stringPath = _docclient.igetdocannexsevicreturnbyreceive (A_ID);//Get file AddressSystem.Net.HttpWebRequest HttpWebRequest =NULL; stringfilename = path. Substring (path. LastIndexOf ("/") +1, Path. Length-path. LastIndexOf ("/") -1);//Get file nameHttpWebRequest =(System.Net.HttpWebRequest) System.Net.HttpWebRequest.Create (path); System.Net.HttpWebResponse HttpWebResponse=(System.Net.HttpWebResponse) httpwebrequest.getresponse (); System.IO.Stream SR=Httpwebresponse.getresponsestream (); returnFile (SR,"text/html", filename); }
. NET download files based on file address