Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从虚拟路径URL asp.net下载文件_C#_Asp.net - Fatal编程技术网

C# 从虚拟路径URL asp.net下载文件

C# 从虚拟路径URL asp.net下载文件,c#,asp.net,C#,Asp.net,我有一个虚拟路径URL(http://xyz.com/eRoom/SPOmidrangesysdiv/EFT3%20Test%20Scorecard%20for%20Inyo.xlsx). 浏览此url所需的凭据。 我想使用ASP.NET C#从url下载文件 您可以使用 您应该使用上面提到的Asif。这是一个可以轻松替换相同基本位置中的备用文件的分解图 string remoteUri = "http://xyz.com/eRoom/SPOmidrangesysdiv/"; string fi

我有一个虚拟路径URL(http://xyz.com/eRoom/SPOmidrangesysdiv/EFT3%20Test%20Scorecard%20for%20Inyo.xlsx). 浏览此url所需的凭据。 我想使用ASP.NET C#从url下载文件

您可以使用

您应该使用上面提到的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\U SERVERNAME)有权写入该目录。

请为此提供c代码。可能与Hi标记重复,我已实现代码并使用{myWebClient.Credentials=new NetworkCredential(“xyz”、“ABC”、“ABC”);}。但我遇到了错误-{System.Net.WebException:远程服务器返回了一个错误:(401)未经授权。}@PintuYadav是资源(也称为文件)您需要凭据才能访问的内容?换句话说,如果您是直接从浏览器导航?如果不是,请尝试将UseDefaultCredentials设置为true,可能是这样的
WebClient myWebClient=new WebClient(){UseDefaultCredentials=true};
我使用了以下代码,但遇到了异常“远程服务器返回错误:(401)Unauthorized”“”WebClient myWebClient=new WebClient();myWebClient.Credentials=new NetworkCredential(“PatPatPathV”、“54rukN6YU”、“corp”);myWebClient.DownloadFile(“,@”C:\\TestScorecard.xlsx”);我使用了以下代码,但出现异常“远程服务器返回错误:(401)未经授权的“'WebClient myWebClient=new WebClient();myWebClient.Credentials=new NetworkCredential(“PatPatPathV”、“54rukN6YU”、“corp”);myWebClient.DownloadFile(“,@”C:\\TestScorecard.xlsx”);
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);