上传文件的方法
方法一:在页面中加入file field控件,并将它改为服务器端控件。
将页面代码中加入:<Form Enctype="multipart/form—data" runat=“Server“ method="Post”>
在上传按钮的代码如下:
String TargetPath = Request.PhysicalApplicationPath + "FileUp\" + Path.GetFileName(MyFile.PostedFile.FileName);
MyFile.PostedFile.SaveAs(TargetPath);
Message.Text = "Your file was successfully uploaded at: <b>" +TargetPath + "</b>";