在页面部分加入 input id=”uplthefile” type=”file” name=”uplthefile” runat=”server” 在代码部分加: void btnU" name="description" />

Uploadfile

发表于:2007-05-25来源:作者:点击数: 标签:mso-ascii-foUploadfileSimSun
MI LY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: EN-CA">在页面部分加入 input id=”uplthefile” type=”file” name=”uplthefile” runat=”server” 在代码部分加: void btnU

MILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: EN-CA">在页面部分加入

<input id=”uplthefile” type=”file” name=”uplthefile” runat=”server”>

在代码部分加:


void btnUploadTheFile_Click(object sender, System.EventArgs e)

{

  if (uplTheFile.PostedFile != null)

 {

    HttpPostedFile mFile= uplTheFile.PostedFile;

   int fileSize = mFile.ContentLength;

if (fileSize==0)

{

 txtErrMsg.InnerText = "No file uploaded, try again";

return;

}

try

{

byte[] mFileByte = new Byte[fileSize];

mFile.InputStream.Read(mFileByte,0,fileSize);

string sFilename = ClientID + System.IO.Path.GetFileName(mFile.FileName);

System.IO.FileStream saveFile = new System.IO.FileStream(Server.MapPath("~/"+Request.QueryString["UploadPath"]+ "/" + sFilename), System.IO.FileMode.Create);

saveFile.Write(mFileByte,0, mFileByte.Length);

saveFile.Close();

}

catch

{

txtErrMsg.InnerText = "File uploaded Unsuclearcase/" target="_blank" >ccessfull, try again";

}

                }

                                }

原文转自:http://www.ltesting.net

评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)