Get filename while downloading it

前端 未结 6 546
抹茶落季
抹茶落季 2020-12-13 13:59

We are providing files that are saved in our database and the only way to retrieve them is by going by their id as in:

www.AwesomeURL.com/AwesomeS

6条回答
  •  被撕碎了的回忆
    2020-12-13 14:55

    I achieve this with the code of wst.

    Here is the full code to download the url file in c:\temp folder

    public static void DownloadFile(string url)
        {
            using (WebClient client = new WebClient())
            {
                client.OpenRead(url);
    
                string header_contentDisposition = client.ResponseHeaders["content-disposition"];
                string filename = new ContentDisposition(header_contentDisposition).FileName;
    
    
                //Start the download and copy the file to the destinationFolder
                client.DownloadFile(new Uri(url), @"c:\temp\" + filename);
            }
    
        }
    

提交回复
热议问题