簡體   English   中英

從虛擬路徑URL asp.net下載文件

[英]Download file from virtual path URL asp.net

我有一個虛擬路徑URL(http://xyz.com/eRoom/SPOmidrangesysdiv/EFT3%20Test%20Scorecard%20for%20Inyo.xlsx)。 瀏覽此URL所需的憑據。 我想使用ASP.NET C#從URL下載文件。

您可以使用WebClient

WebClient client = new System.Net.WebClient();
// You might require some headers to be added for authentication
client.AddHeader("header", "header"); 
byte[] data = client.DownloadData("http://xyz.com/eRoom/SPOmidrangesysdiv/EFT3%20Test%20Scorecard%20for%20Inyo.xlsx")'

您應該將WebClient用作上述Asif。 分解后可以輕松地在同一基本位置替換備用文件。

string remoteUri = "http://xyz.com/eRoom/SPOmidrangesysdiv/";
string fileName = "EFT3%20Test%20Scorecard%20for%20Inyo.xlsx", myStringWebResource = null;
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
// Concatenate the domain with the Web resource filename.
myStringWebResource = remoteUri + fileName;
myWebClient.DownloadFile(myStringWebResource,fileName);        

您可以在DownloadFile方法的第二個參數中指定目錄,只需確保您的IIS用戶(通常是SERVERNAME \\ IUSR_ SERVERNAME )有權訪問該目錄。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM