日期:2014-05-17 浏览次数:20420 次
protected void Button1_Click(object sender, EventArgs e)
{
string UploadFile = "";
if (this.UploadFile.HasFile)
{
UploadFile = this.UploadFile.PostedFile.FileName.ToString();
string strFileName = Path.GetExtension(this.UploadFile.PostedFile.FileName).ToUpper();//获取文件后缀
if (!(strFileName == ".FLV"))
{
Response.Write("<script Language=Javascript>alert('文件格式不正确!');</script>");
return;
}
Random ran = new Random();
string sNewName = DateTime.Now.ToString(@"yyyyMMddHHmmss") + ran.Next(100, 999)
+ Path.GetExtension(this.UploadFile.PostedFile.FileName);
string strPath = Server.MapPath("~/FileUpload/" + sNewName);
if (!Directory.Exists(Path.GetDirectoryName(strPath)))
{
Directory.CreateDirectory(Path.GetDirectoryName(strPath));
}
this.UploadFile.PostedFile.SaveAs(strPath);
}
}