62,073
社区成员
发帖
与我相关
我的任务
分享
protected void btnupload_Click(object sender, EventArgs e)
{
Boolean fileOK = false;
String path = Server.MapPath("~/UploadFiles/");
if (fuupload.HasFile)
{
String fileExtension = System.IO.Path.GetExtension(fuupload.FileName).ToLower();
String[] allowedExtensions = { ".txt", ".doc", ".xml", ".jpg",".exe" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
}
}
}
//如果文件类型符合
if (fileOK)
{
try
{
// 将文件保存到指定的文件夹下
fuupload.PostedFile.SaveAs(path + fuupload.FileName);
labmsg.Text = "File Upload Succeed!";
}
catch
{
labmsg.Text = "Upload Fail!";
}
}
else
{
labmsg.Text = "File Type or Size is Unallowed!";
}
}