0
這裏下載文件時出錯我寫了簡單的C#代碼下載Excel工作表從的WebAPI 但下載即時得到誤差The given path's format is not supported.
期間 請幫我不支持給定路徑的格式。從Asp.net阿比
public HttpResponseMessage GetTestFile()
{
HttpResponseMessage result = null;
// var localFilePath = HttpContext.Current.Server.MapPath(@"~/C:/Temp/3c575edb-bf53-470c-a8b6-aa4234e796c0");
var localFilePath = HttpContext.Current.Server.MapPath(@"~/C:/Temp/3c575edb-bf53-470c-a8b6-aa4234e796c0");
if (!File.Exists(localFilePath))
{
result = Request.CreateResponse(HttpStatusCode.Gone);
}
else
{
// Serve the file to the client
result = Request.CreateResponse(HttpStatusCode.OK);
result.Content = new StreamContent(new FileStream(localFilePath, FileMode.Open, FileAccess.Read));
result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
result.Content.Headers.ContentDisposition.FileName = "SampleImg";
}
return result;
}
是它我的項目 – Hussain
「System.NotSupportedException」類型的異常之內prsenet出現在mscorlib.dll,但在用戶代碼中沒有處理 – Hussain
//這將查找文件example.txt的在根目錄下。 // ...這可以用在應用程序中任何目錄中的文件中。 'string localFilePath = HttpContext.Current.Request.MapPath(「〜/ Example.txt」);'。有想法?所以你的情況是'3c575edb-bf53-470c-a8b6-aa4234e796c0'文件夾? –