在页面部分加入 input id=”uplthefile” type=”file” name=”uplthefile” runat=”server” 在代码部分加: void btnU" name="description" />
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";
}
}
}