作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果我有一个包含多个输入文件字段的 HTML 表单(其中“N”是唯一编号);
<input type="file" name="inputFileN">
然后在C#代码中;
string inFile = System.IO.Path.GetFileName(Request.Files[M].FileName)
有什么方法可以从请求数据中确定“M”的值,以便我可以匹配特定的 HTML 输入文件类型字段?
这是在最终用户可以更新编辑表单上的字段的情况下,它适用于除文件类型字段之外的所有字段类型。
最佳答案
所有必要的数据都在 HttpContext.Request.Files
中;具体来说,在 HttpContext.Request.Files.AllKeys
中:
//HttpContext is a member of `System.Web.Mvc.Controller`,
//accessible in controllers that inherit from `System.Web.Mvc.Controller`.
System.Web.HttpFileCollectionBase files = HttpContext.Request.Files;
string[] fieldNames = files.AllKeys;
for (int i = 0; i < fieldNames.Length; ++i)
{
string field = fieldNames[i]; //The 'name' attribute of the html form
System.Web.HttpPostedFileBase file = files[i];
string fileName = files[i].FileName; //The path to the file on the client computer
int len = files[i].ContentLength; //The length of the file
string type = files[i].ContentType; //The file's MIME type
System.IO.Stream stream = files[i].InputStream; //The actual file data
}
关于c# - C# Request.Files[n].FileName 的哪个文件表单字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22057680/
我尝试通过正则表达式将文本中的单引号更改为双引号。 (单字)示例:我走了。 You gona fly to planet 'Ziqtos' => 我需要在 I'm 中保留单引号,并在 You gona
我正在构建一个 API,其中大部分将包含 JSON 和 HTML 内容。但是一些非常具体的端点只呈现 true 或 false,并且还在 POST 中接受 true 或 false。这是请求或响应的整
我是一名优秀的程序员,十分优秀!