上傳圖片:
private string UploadPic()
...{
if(txtPictureUploader.PostedFile.FileName.Length ==0)
...{
return string.Empty ;
}
string fileName = Guid.NewGuid().ToString();
int position = txtPictureUploader.PostedFile.FileName.LastIndexOf(".");
if(position == -1)
...{
throw new Exception("上傳的文件格式不正確!");
}
string extensionName = txtPictureUploader.PostedFile.FileName.Substring(position).ToLower();
if(extensionName == ".png"||extensionName == ".jpg"||extensionName == ".gif"||extensionName == ".jpeg"||extensionName == ".bmp")
...{
string filePath=ConfigurationSettings.APPSettings["UploadVideoImagePath"];
fileName = fileName+extensionName;
if(filePath==null)
filePath ="/Picture/Video/Images/";
txtPictureUploader.PostedFile .SaveAs(Server.MapPath( filePath)+ fileName) ;
return fileName;
}
else
...{
throw new Exception("上傳的文件格式不正確!");
}
}
上傳視頻:
private string UploadVideo()
...{
if(txtVideoFileUploader.FileName.Length ==0)
...{
return string.Empty ;
}
string fileName = Guid.NewGuid().ToString();
int position = txtVideoFileUploader.FileName.LastIndexOf(".");
if(position == -1)
...{
throw new Exception("上傳的文件格式不正確!");
}
string extensionName = txtVideoFileUploader.FileName.Substring(position);
string filePath=ConfigurationSettings.APPSettings["UploadVideosPath"];
fileName = fileName+extensionName;
if(filePath==null)
filePath ="/Picture/Video/Videos/";
txtVideoFileUploader.MoveTo(Server.MapPath(filePath+fileName),MoveToOptions.Overwrite);
return fileName;
}