Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.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# 将文件上载到asp服务器_C#_Asp.net_Webclient_Webclient.uploaddata - Fatal编程技术网

C# 将文件上载到asp服务器

C# 将文件上载到asp服务器,c#,asp.net,webclient,webclient.uploaddata,C#,Asp.net,Webclient,Webclient.uploaddata,我需要将文本文件从我的桌面应用程序上传到我主持的Web服务器。我遵循了本教程,但在运行代码时出现了此错误。 远程服务器返回错误500内部服务器错误 客户端代码,即桌面应用程序 String uriString = "http://localhost:3045/WebForm1.aspx"; // Create a new WebClient instance. WebClient myWebClient = new WebClient(); string fileName = @"C:\Us

我需要将文本文件从我的桌面应用程序上传到我主持的Web服务器。我遵循了本教程,但在运行代码时出现了此错误。 远程服务器返回错误500内部服务器错误

客户端代码,即桌面应用程序

String uriString = "http://localhost:3045/WebForm1.aspx";

// Create a new WebClient instance.
WebClient myWebClient = new WebClient();

string fileName = @"C:\Users\Administrator\Documents\Visual Studio 2010\Projects\FYP Modules\FileUploader\abc.txt";
MessageBox.Show("Uploading " + fileName + " To " + uriString);

// Upload the file to the URI. 
// The 'UploadFile(uriString,fileName)' method implicitly uses HTTP POST method. 
byte[] responseArray = myWebClient.UploadFile(uriString, fileName);




// Decode and display the response.
MessageBox.Show("\nResponse Received.The contents of the file uploaded are:\n{0}",
                System.Text.Encoding.ASCII.GetString(responseArray));
服务器端代码,即asp.net webform

<%@ Import Namespace="System"%>
<%@ Import Namespace="System.IO"%>
<%@ Import Namespace="System.Net"%>
<%@ Import NameSpace="System.Web"%>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<Script language="C#" runat="server">

void Page_Load(object sender, EventArgs e) {

foreach(string f in Request.Files.AllKeys) {
    HttpPostedFile file = Request.Files[f];
    file.SaveAs("c:\\inetpub\\test\\UploadedFiles\\" + file.FileName);
}   
}

</Script>



<p> Upload complete.  </p>

</asp:Content>

异常详细信息是什么?您的站点有权写入c:\inetpub\test\UploadedFiles吗?我想我有。这只是一个位置为什么在这个用例中使用WebForms?处理者呢?还是ASP.NET Web API REST?你能稍微润色一下吗。事实上,这是我第一次做这样的事情