现在的位置: 首页 > 综合 > 正文

上传文件的方法

2012年10月04日 ⁄ 综合 ⁄ 共 345字 ⁄ 字号 评论关闭
 

方法一:在页面中加入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>";

抱歉!评论已关闭.