/// <summary> /// 图集上传 /// </summary> /// <returns></returns> private Boolean SaveImages() { HttpFileCollection files = HttpContext.Current.Request.Files; try { MSForumTopicAtlas atlasModel = new MSForumTopicAtlas(); atlasModel.TID = strTid; for (int iFile = 0; iFile < files.Count; iFile++) { //检查文件扩展名字 HttpPostedFile postedFile = files[iFile]; string fileName, fileExtension, file_oldid, file_id; //取出精确到毫秒的时间做文件的名称 string my_file_id = DateTime.Now.ToString("yyyyMMddHHmmssfff") + iFile.ToString(); fileName = System.IO.Path.GetFileName(postedFile.FileName); fileExtension = System.IO.Path.GetExtension(fileName); file_id = my_file_id + fileExtension; if (fileName != "" && fileName != null && fileName.Length > 0) { fileExtension = System.IO.Path.GetExtension(fileName); string saveurl, modelimgurl; saveurl = modelimgurl = "ForumImg/"; saveurl = Server.MapPath(saveurl); if (!Directory.Exists(saveurl)) { Directory.CreateDirectory(saveurl); } int length = postedFile.ContentLength; if (length > 512000) { file_oldid = "old" + file_id; postedFile.SaveAs(saveurl + file_oldid); JQDialog.ystp(saveurl + file_oldid, saveurl + file_id, 15); File.Delete(saveurl + file_oldid); } else { postedFile.SaveAs(saveurl + file_id); } atlasModel.ID = Guid.NewGuid().ToString("N").ToUpper(); atlasModel.ImgState = 0; atlasModel.ImgUrl = modelimgurl + file_id; atlasModel.ImgName = topictitle; MSForumTopicAtlasDAL atlasDal = new MSForumTopicAtlasDAL(); atlasDal.AddMSForumTopicAtlas(atlasModel); } } return(true); } catch (System.Exception Ex) { return(false); } }
string UploadImg(string strImgName) { HttpFileCollection files = Request.Files; string fileName, fileExtension, file_oldid; string file_id = string.Empty; if (strImgName != null && strImgName != "") { //检查文件扩展名字 HttpPostedFile postedFile = files[strImgName]; //取出精确到毫秒的时间做文件的名称 string my_file_id = DateTime.Now.ToString("yyyyMMddHHmmssfff"); fileName = System.IO.Path.GetFileName(postedFile.FileName); fileExtension = System.IO.Path.GetExtension(fileName); file_id = my_file_id + fileExtension; if (fileName != "" && fileName != null && fileName.Length > 0) { fileExtension = System.IO.Path.GetExtension(fileName); string saveurl; saveurl = "ShopLogo/"; saveurl = Server.MapPath(saveurl); if (!Directory.Exists(saveurl)) { Directory.CreateDirectory(saveurl); } int length = postedFile.ContentLength; if (length > 512000) { file_oldid = "old" + file_id; postedFile.SaveAs(saveurl + file_oldid); JQDialog.ystp(saveurl + file_oldid, saveurl + file_id, 15); File.Delete(saveurl + file_oldid); } else { postedFile.SaveAs(saveurl + file_id); } } } return(file_id); }
/// <summary> /// 图集上传 /// </summary> /// <returns></returns> bool SaveImages() { bool result = false; if (customerid != null && customerid != "") { MSCustomersDAL customer = new MSCustomersDAL(); phone = customer.GetCustomerValueByID("Phone", customerid).ToString() + "/"; } HttpFileCollection files = HttpContext.Current.Request.Files; try { MSProductAtlas atlasModel = new MSProductAtlas(); MSProductAtlasDAL atlasDal = new MSProductAtlasDAL(); atlasModel.PID = pid; for (int iFile = 0; iFile < files.Count; iFile++) { //检查文件扩展名字 HttpPostedFile postedFile = files[iFile]; string fileName, fileExtension, file_oldid, file_id; //取出精确到毫秒的时间做文件的名称 string my_file_id = DateTime.Now.ToString("yyyyMMddHHmmssfff") + iFile.ToString(); fileName = System.IO.Path.GetFileName(postedFile.FileName); fileExtension = System.IO.Path.GetExtension(fileName); file_id = my_file_id + fileExtension; if (fileName != "" && fileName != null) { fileExtension = System.IO.Path.GetExtension(fileName); string saveurl, modelimgurl; saveurl = modelimgurl = "Atlas/" + phone; saveurl = Server.MapPath(saveurl); if (!Directory.Exists(saveurl)) { Directory.CreateDirectory(saveurl); } int length = postedFile.ContentLength; if (length > 512000) { file_oldid = "old" + file_id; postedFile.SaveAs(saveurl + file_oldid); JQDialog.ystp(saveurl + file_oldid, saveurl + file_id, 15); File.Delete(saveurl + file_oldid); } else { postedFile.SaveAs(saveurl + file_id); } atlasModel.ID = Guid.NewGuid().ToString("N").ToUpper(); if (iFile == 0) { if (!atlasDal.IsExitDefaultImg(pid)) { atlasModel.IsDefault = 1; } } atlasModel.ImgState = 0; atlasModel.PimgUrl = modelimgurl + file_id; atlasModel.AtlasName = ""; if (atlasDal.AddMSProductAtlas(atlasModel)) { result = true; } } } } catch (System.Exception Ex) { result = false; } return(result); }
void editeCustomerinfo() { string nickname = string.Empty; string modelimgurl = string.Empty; try { nickname = HttpContext.Current.Request.Form.Get("nickname").ToString(); } catch (Exception) { nickname = ""; } MSCustomers customerModel = new MSCustomers(); MSCustomersDAL customerDal = new MSCustomersDAL(); customerModel.ID = strUid; if (nickname != null && nickname != "") { #region -----------------头像上传------------------- HttpFileCollection files = HttpContext.Current.Request.Files; if (files.Count > 0) { //检查文件扩展名字 HttpPostedFile postedFile = files[0]; string fileName, fileExtension, file_oldid, file_id; //取出精确到毫秒的时间做文件的名称 string my_file_id = DateTime.Now.ToString("yyyyMMddHHmmssfff"); fileName = System.IO.Path.GetFileName(postedFile.FileName); fileExtension = System.IO.Path.GetExtension(fileName); file_id = my_file_id + fileExtension; if (fileName != "" && fileName != null && fileName.Length > 0) { fileExtension = System.IO.Path.GetExtension(fileName); string saveurl; modelimgurl = "HeadImg/"; saveurl = "../PalmShop/ShopCode/" + modelimgurl; saveurl = Server.MapPath(saveurl); if (!Directory.Exists(saveurl)) { Directory.CreateDirectory(saveurl); } int length = postedFile.ContentLength; if (length > 512000) { file_oldid = "old" + file_id; postedFile.SaveAs(saveurl + file_oldid); JQDialog.ystp(saveurl + file_oldid, saveurl + file_id, 15); File.Delete(saveurl + file_oldid); } else { postedFile.SaveAs(saveurl + file_id); } modelimgurl = modelimgurl + file_id; } } #endregion customerModel.NickName = nickname; if (modelimgurl != null && modelimgurl != "") { customerModel.HeadImg = modelimgurl; } customerModel.IsDel = 0; if (customerDal.UpdateCustomers(customerModel)) { if (modelimgurl != null && modelimgurl != "") { if (oldimgname != null && oldimgname != "") { File.Delete(String.Format(@"{0}PalmShop/ShopCode/{1}", Server.MapPath("~"), oldimgname)); } } errorscript = JQDialog.alertOKMsgBox(3, "操作成功", "MyTopicList.aspx?fid=" + strfid, "succeed"); } else { errorscript = JQDialog.alertOKMsgBox(3, "操作失败,请核对后再操作", "Customerinfo.aspx?fid=" + strfid, "error"); } } else { errorscript = JQDialog.alertOKMsgBox(3, "操作失败,请核对后再操作", "Customerinfo.aspx?fid=" + strfid, "error"); } }