I am working on an asp.net application. I am showing user the list of files from a shared folder on network and I want user to be able to download any file from the list. But I am not able to locate that file in the code I get Invalid URI: The format of the URI could not be determined.
error.
Code block -
var uri = new Uri(filePath); // Here I get the error
var fName = Path.GetFullPath(uri.LocalPath);
var fileInfo = new FileInfo(fName);
var response = HttpContext.Current.Response;
response.Clear();
response.ClearContent();
response.ClearHeaders();
response.Buffer = true;
response.AddHeader("Content-Description", "attachment;filename="+fileInfo.FullName);
response.WriteFile(fileInfo.FullName);
response.End();
Please suggest how can I get to that file and give it to the response header so that it could be downloaded.
使用Verbatim文字 :
var filePath = @"\\server\somefolder\somefolder\file.txt"
using the path in below format fixed the issue -
\\\\server\\somefolder\\somefolder\\file.txt
suggested by @avijit
Simply use
response.WriteFile(filePath);
There is no reason to use a URI.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.