日期:2014-05-17 浏览次数:20445 次
<asp:FileUpload ID="FileUpload_Upload" runat="server" CssClass="textbox" />
<asp:Button ID="Button_Uploadfile" runat="server"
Text="Upload" CssClass="textbox" style="cursor:hand"
onclick="Button_Uploadfile_Click" />
//没文件夹创建文件夹
public void FolderPath(string pathStr)
{
if (!Directory.Exists(pathStr))
{
Directory.CreateDirectory(pathStr);
}
}
//按钮触发
protected void Button_Uploadfile_Click(object sender, EventArgs e)
{
string ServerPath = System.Web.HttpContext.Current.Request.MapPath("upload/"+DateTime.Now.ToString("yyyyMMdd"));
if (!string.IsNullOrEmpty(this.FileUpload_Upload.PostedFile.FileName))
{
FolderPath(ServerPath);
string Sion = Path.GetExtension(this.FileUpload_Upload.FileName);
string file = Path.GetFileNameWithoutExtension(this.FileUpload_Upload.FileName);
string FileName =file+ DateTime.Now.ToString("yyyyMMddHHmmssFFFFF")+Sion;
this.FileUpload_Upload.PostedFile.SaveAs(ServerPath + "/" + FileName );
//Alert("Upload success");
}
else {
//Alert("Please Select File To Upload!");
}
}