gb2*_*b2d 0 c# asp.net web-applications
我很清楚如何使用标准的ASP.NET技术从客户端到服务器获取文件,但是,我需要能够从用基本html编写的第三方网页检索数据并处理文件数据在asp.net Web应用程序中.
所以,如果基本的HTML看起来像这样......
<form id="form1" action="WebForm.aspx" method="post">
<input name="fileUpload1" type="file" enctype="multipart/form-data" />
<input type="submit" value="click" />
</form>
Run Code Online (Sandbox Code Playgroud)
如何在表单的action属性中引用的页面中检索文件数据.到目前为止,我已经尝试了下面的代码,它允许我访问文件名 - 但不是文件的字节流.
protected void Page_Load( object sender, EventArgs e )
{
string fileName = Request.Form["fileUpload1"];
// No files appear in the request.files collection in code below.
foreach (string file in Request.Files)
{
HttpPostedFile hpf = Request.Files[file] as HttpPostedFile;
if (hpf.ContentLength == 0)
continue;
string savedFileName = Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
Path.GetFileName( hpf.FileName ) );
hpf.SaveAs( savedFileName );
}
}
Run Code Online (Sandbox Code Playgroud)
任何建议都非常感谢.
你的表格不正确.该enctype参数应该在form标签:
<form id="form1" action="WebForm.aspx" method="post" enctype="multipart/form-data">
<input name="fileUpload1" type="file" />
<input type="submit" value="click" />
</form>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1346 次 |
| 最近记录: |