保存图片
选择图片并上传,保存在指定文件夹下,图片名为 图片名+创建时间。
文件夹按月(或者星期)创建。
求代码 图片 .net保存图片
[解决办法]
前台:
<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!");
}
}
}
file.SaveAs(savePath +'/'+newName); //将上传的文件保存到指定的目录。
ViewData["messageBox"] = "上传成功";
ps:这算是很完整的了