保存图片 图片.net保存图片 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 创建目录:Directory.CreateDirectory文件名的问题在另一个帖子中回答你了。 前台: <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!"); } } string timeStamp = DateTime.Now.ToString("yyyyMM"); string path = Server.MapPath("/uploadfile/" + timeStamp); if (!Directory.Exists(path)) Directory.CreateDirectory(path); string usename = users[0].CUserName.ToString(); //获取用户名 string randomName = DateTime.Now.ToFileTime().ToString(); //系统当前时间为图片名称 //string path = Request.MapPath("~/Content/images"); HttpPostedFileBase file = Request.Files["fileToUpload"];//获取页面上获取图片内容["fileToUpload"] 是页面上上传图片空间的name string pictureName = file.FileName;//上传图片的原名 string extensionName = System.IO.Path.GetExtension(pictureName);//获取扩展名 int randomcode = BaseRandom.GetRandom(1000, 9999); //产生随机数 string newName = string.IsNullOrEmpty(pictureName.Trim()) ? "" : usename + randomcode + randomName + System.IO.Path.GetExtension(pictureName); //重命名图片 string savePath = HttpContext.Server.MapPath("~/Content/Uploads/img/" + usename); //原图图片保存位置 if (!System.IO.Directory.Exists(savePath)) { //如果路径不存在创建新文件夹 System.IO.Directory.CreateDirectory(savePath); } file.SaveAs(savePath +'/'+newName); //将上传的文件保存到指定的目录。 ViewData["messageBox"] = "上传成功";ps:这算是很完整的了 哪位能直线这种效果窗体效果~~ 被正则教程搞晕了,进来讨论下下,分 学技术 搞java asp.net php 最终的目的是什么?? 可以在用户控件中使用PopupControlExtender吗 关于验证控件的简单问题 什么叫分布式编程? 很急:一个asp.net开发过程中的问题! 如何在 asp.net 中避免 刷新页面 导致的表单数据重复提交? 关于验证是否为空 media service 配置 问题严重 播放自己的流 C# 继承 做的网站部署在IIS上登录状态是500
Directory.CreateDirectory文件名的问题在另一个帖子中回答你了。
<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!");
}
}
string timeStamp = DateTime.Now.ToString("yyyyMM");
string path = Server.MapPath("/uploadfile/" + timeStamp);
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
string randomName = DateTime.Now.ToFileTime().ToString(); //系统当前时间为图片名称
//string path = Request.MapPath("~/Content/images");
HttpPostedFileBase file = Request.Files["fileToUpload"];//获取页面上获取图片内容["fileToUpload"] 是页面上上传图片空间的name
string pictureName = file.FileName;//上传图片的原名
string extensionName = System.IO.Path.GetExtension(pictureName);//获取扩展名
int randomcode = BaseRandom.GetRandom(1000, 9999); //产生随机数
string newName = string.IsNullOrEmpty(pictureName.Trim()) ? "" : usename + randomcode + randomName + System.IO.Path.GetExtension(pictureName); //重命名图片
string savePath = HttpContext.Server.MapPath("~/Content/Uploads/img/" + usename); //原图图片保存位置
if (!System.IO.Directory.Exists(savePath))
{
//如果路径不存在创建新文件夹
System.IO.Directory.CreateDirectory(savePath);
}
file.SaveAs(savePath +'/'+newName); //将上传的文件保存到指定的目录。
ViewData["messageBox"] = "上传成功";
ps:这算是很完整的了