ASP.NET FileUpload 文件上传控件 |
2021-01-21 17:22:10 35资源网(www.35d.net) |
.net |
下载本资源原文网址:http://www.daima.org/net/net4821.html 需要在要目录下新建两个目录:upfile和upimg 添加一个FileUpload控件.一个Button.一个Image.一个Label
关键代码: string name = FileUpload1.FileName;//获得上传文件的名字. string size = FileUpload1.PostedFile.ContentLength.ToString();//文件大小. string type = FileUpload1.PostedFile.ContentType;//文件类型. string type2 = name.Substring(name.LastIndexOf(".") + 1);//LastIndexOf()最后一个索引位置匹配.Substring()里面的+1是重载. string ipath = Server.MapPath("upimg") + "//" + name;//取得根目录下面的upimg目录的路径. string fpath = Server.MapPath("upfile") + "//" + name; string wpath = "upimg//" + name;//获得虚拟路径. if (type2 == "jpg" || type2 == "gif" || type2 == "bmp" || type2 == "png") { FileUpload1.SaveAs(ipath);//保存方法,参数是一个地址字符串. Image1.ImageUrl = wpath; Label1.Text = "你传的文件名是:" + name + "<br>文件大小为:" + size + "字节<br>文件类型是:" + type + "<br>后缀是:" + type2 + "<br>实际路径是:" + ipath + "<br>虚拟路径是:" + fpath; Image1.Visible = true; } else { Image1.Visible = false; FileUpload1.SaveAs(fpath); Label1.Text = "你传的文件名是:" + name + "<br>文件大小为:" + size + "字节<br>文件类型是:" + type + "<br>后缀是:" + type2 + "<br>实际路径是:" + ipath + "<br>虚拟路径是:" + fpath; } |
|
|
|
资源大全_资源下载网站:www.35d.net 本站资源仅限研究学习使用,如需商用请联系版权方, 本站事务联系QQ:939804642
|
|