c# - 在UploadFile之后,Request.Files总是空的

时间:2015-12-17 17:29:15

标签: c# asp.net winforms webforms

我尝试将文件从Windows窗体c#客户端应用程序上传到ASP.NET C#应用程序。 实际上我在客户端应用程序中运行此代码:

WebClient uploader = new WebClient();
string UploadFilePath = "<filepath>";
string uploadWebUrl = "http://localhost:51037/(S(044401gmyxhg3uz01ulngfdp))/upload.aspx";
byte[] responseArray = uploader.UploadFile(uploadWebUrl, UploadFilePath);

这是upload.aspx页面

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

<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("~/Download/"+file.FileName);
    }   
}

</Script>
<html>
<body>
<p> Upload complete.  </p>
</body>
</html>

关键在于,实际上,&#34; Request.Files&#34;是一个空字符串数组,我不明白为什么

1 个答案:

答案 0 :(得分:0)

我认为您只需要在上传文件命令中添加“POST”:

<div ng-repeat='thing in ctrl.list'>
   {{thing.property[0].anotherProp}}
</div>

以下是Microsoft的文档:https://msdn.microsoft.com/en-us/library/aa329790(v=vs.71).aspx

其中,这是UploadFile的方法签名:

byte[] responseArray = uploader.UploadFile(uploadWebUrl, "POST", UploadFilePath);