C#中$ _FILES的等价物

Bri*_*cks 2 c# asp.net

什么是C#中PHP的$ _FILES变量的等价物?或者至少以相同方式访问文件的东西.我有一个上传表单,我无法更改,需要找到如何获取这些文件.

Rob*_*Rob 9

看看Request.Files,例如:

foreach (HttpPostedFile item in Request.Files)
{
    var filename = item.FileName;

    var fileBytes = new byte[item.ContentLength];
    item.InputStream.Read(fileBytes, 0, item.ContentLength);

    // fileBytes now contains the content of the file
    // filename contains the name of the file
}
Run Code Online (Sandbox Code Playgroud)

  • 蒂姆维,我相信你会因为你的错误向罗巴道歉.除非你想说http://msdn.microsoft.com/en-us/library/system.web.httppostedfile.inputstream.aspx上的HttpPostedFile.InputStream文档使用Rob正在使用的相同示例是错误的.此外,如果您懒得使用Reflector检查HttpInputStream,您将看到它包含内存中的整个文件内容并返回所有可用字节.最后,Save和Read将使用相同的参数调用相同的GetBytes方法.看来你需要不知道溪流和你想的那样 (3认同)