zl程序教程

您现在的位置是:首页 >  后端

当前栏目

asp.net中通过input file上传文件

Net文件ASP上传 通过 File input
2023-06-13 09:12:16 时间

大家好,又见面了,我是你们的朋友全栈君。

前台:

<input id=”htmlFile” type=”file” runat=”server” />

后台:

if (Request.Files.Count > 0) { HttpPostedFile file = Request.Files[0];

int index = file.FileName.LastIndexOf(“\\”); int length = file.FileName.Length – index – 1;

string file_name = file.FileName.Substring(index + 1, length); file.SaveAs(this.Server.MapPath(“~/Files/” + file_name));

Response.Write(“<script type=’text/javascript’>alert(‘Upload Success!’);</script>”); }

此外还需注意,在asp.net的中使用<input type=”file” />控件上传文件时是有大小限制的,可通过修改web.config文件中的参数来进行设置:

在<system.web>节点下增加<httpRuntime maxRequestLength=”102400″/>一项(该属性是以字节为单位)

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/160975.html原文链接:https://javaforall.cn