首先、在WEBFORM的HTML中将FORM的属性修改为如下:
<form id="Form1" method="post"enctype="multipart/form-data" runat="server">
并将myFile控件作为服务器端的控件进行使用。
然后在代码编辑器中写
if(myFile.PostedFile!=null)
{
string nam = myFile.PostedFile.FileName ;
int i= nam.LastIndexOf("\\") ;
string newnm =nam.Substring(i) ;
if(File.Exists(Server.MapPath("image\\")+newnm))//判断文件是否存在
{
Label1.Text="此文件名在服务器上已存在!!";
}
myFile.PostedFile.SaveAs(Server.MapPath("image\\")+newnm) ;
TextBox1.Text=myFile.PostedFile.FileName;
TextBox2.Text=myFile.PostedFile.ContentType ;
TextBox3.Text=myFile.PostedFile.ContentLength.ToString();
}