if (FileUpload1.HasFile)
{
string fileType = System.IO.Path.GetExtension(FileUpload1.FileName);
string fileName = DateTime.Now.ToString().Replace(" ","").Replace("/","").Replace(":","");
int fileLength = FileUpload1.PostedFile.ContentLength / 1024;
if (fileType != ".jpg" && fileType != ".gif" && fileType != ".bmp")
{
DialogBox("上传文件的类型仅支持.jpg .gif .bmp,请重试!");
return;
}
if (fileLength > 500)
{
DialogBox("上传文件的大小不能超过500K,请重试!");
return;
}
string postFilePath = Server.MapPath("~/uploadFile2");
if (!System.IO.Directory.Exists(postFilePath))
{
System.IO.Directory.CreateDirectory(postFilePath); //创建该目录
}
postFilePath += "\\" + fileName + fileType;
FileUpload1.SaveAs(postFilePath);
}
{
string fileType = System.IO.Path.GetExtension(FileUpload1.FileName);
string fileName = DateTime.Now.ToString().Replace(" ","").Replace("/","").Replace(":","");
int fileLength = FileUpload1.PostedFile.ContentLength / 1024;
if (fileType != ".jpg" && fileType != ".gif" && fileType != ".bmp")
{
DialogBox("上传文件的类型仅支持.jpg .gif .bmp,请重试!");
return;
}
if (fileLength > 500)
{
DialogBox("上传文件的大小不能超过500K,请重试!");
return;
}
string postFilePath = Server.MapPath("~/uploadFile2");
if (!System.IO.Directory.Exists(postFilePath))
{
System.IO.Directory.CreateDirectory(postFilePath); //创建该目录
}
postFilePath += "\\" + fileName + fileType;
FileUpload1.SaveAs(postFilePath);
}