/// <summary> /// 缩略图的生成 /// </summary> private void PushThumbnail() { //根据ID查询出缩略的方式 Int32 ItemID = WebHelper.GetIntParam(Request, "ID", 0); Int32 Width = WebHelper.GetIntParam(Request, "width", 200); Int32 height = WebHelper.GetIntParam(Request, "height", 200); String Mode = WebHelper.GetStringParam(Request, "mode", "AUTO"); String PhotoType = WebHelper.GetStringParam(Request, "Type", "p").ToLower(); String ImagePath = MapPath(String.Format("{0}/Resource/images/no_image.png", TemplateSourceDirectory)); //if (ItemID > 0) //{ // DNNGo_LayerGallery_Content ContentItem = DNNGo_LayerGallery_Content.FindByID(ItemID); // if (ContentItem != null && ContentItem.ID > 0) // { // if (PhotoType == "p") // ImagePath = ViewLinkUrl(ContentItem.Picture, ContentItem.PortalId); // else // ImagePath = ViewLinkUrl(ContentItem.Thumbnails, ContentItem.PortalId); // } //} GenerateThumbnail.PushThumbnail(Server.UrlDecode(ImagePath), Width, height, Mode); }
/// <summary> /// 状态应用按钮事件 /// </summary> protected void btnApply_Click(object sender, EventArgs e) { try { Int32 Status = WebHelper.GetIntParam(Request, ddlStatus.UniqueID, -1); if (Status >= 0) { string Checkbox_Value = WebHelper.GetStringParam(Request, "Checkbox", ""); string[] Checkbox_Value_Array = Checkbox_Value.Split(','); Int32 IDX = 0; mTips.IsPostBack = true; for (int i = 0; i < Checkbox_Value_Array.Length; i++) { if (Int32.TryParse(Checkbox_Value_Array[i], out IDX)) { DNNGo_LayerGallery_Files Multimedia = DNNGo_LayerGallery_Files.FindByKeyForEdit(IDX); if (Multimedia != null && Multimedia.ID > 0) { //if (Multimedia.Status == (Int32)EnumFileStatus.Recycle && Status == (Int32)EnumFileStatus.Recycle) //{ //要删除实际的文件 String DeletePath = Server.MapPath(GetPhotoPath(Multimedia.FilePath)); if (Multimedia.Delete() > 0) { //删除文件 if (File.Exists(DeletePath)) { File.Delete(DeletePath); } //操作成功 mTips.LoadMessage("DeleteMediaLibrarySuccess", EnumTips.Success, this, new String[] { Multimedia.FileName }); } else { //操作失败 mTips.LoadMessage("DeleteMediaLibraryError", EnumTips.Success, this, new String[] { Multimedia.FileName }); } //} //else //{ // Multimedia.Status = Status; // if (Multimedia.Update() > 0) // { // } //} } } } BindDataList(); } } catch (Exception ex) { ProcessModuleLoadException(ex); } }
// Delete file from the server private void DeleteFile(HttpContext context) { Int32 PhotoID = WebHelper.GetIntParam(context.Request, "ID", 0); DNNGo_LayerGallery_Files PhotoItem = DNNGo_LayerGallery_Files.FindByKeyForEdit(PhotoID); if (PhotoItem != null && PhotoItem.ID > 0) { //要删除实际的文件 String DeletePath = HttpContext.Current.Server.MapPath(GetPhotoPath(PhotoItem.FilePath)); //删除文件 if (File.Exists(DeletePath)) { try { File.Delete(DeletePath); } catch { } } //删除记录 PhotoItem.Delete(); } }
// Upload entire file private void UploadWholeFile(HttpContext context, List <Resource_FilesStatus> statuses) { for (int i = 0; i < context.Request.Files.Count; i++) { var file = context.Request.Files[i]; if (file != null && !String.IsNullOrEmpty(file.FileName) && file.ContentLength > 0) { DNNGo_LayerGallery_Files PhotoItem = new DNNGo_LayerGallery_Files(); PhotoItem.ModuleId = WebHelper.GetIntParam(context.Request, "ModuleId", 0); PhotoItem.PortalId = WebHelper.GetIntParam(context.Request, "PortalId", 0); PhotoItem.FileName = file.FileName; PhotoItem.FileSize = file.ContentLength / 1024; PhotoItem.FileMate = FileSystemUtils.GetContentType(Path.GetExtension(PhotoItem.FileName).Replace(".", "")); PhotoItem.FileExtension = System.IO.Path.GetExtension(PhotoItem.FileName).Replace(".", ""); PhotoItem.Name = System.IO.Path.GetFileName(file.FileName).Replace(Path.GetExtension(PhotoItem.FileName), ""); PhotoItem.Status = (Int32)EnumFileStatus.Approved; try { if (("png,gif,jpg,jpeg,bmp").IndexOf(PhotoItem.FileExtension) >= 0) { //图片的流 Image image = Image.FromStream(file.InputStream); PhotoItem.ImageWidth = image.Width; PhotoItem.ImageHeight = image.Height; PhotoItem.Exif = Common.Serialize <EXIFMetaData.Metadata>(new EXIFMetaData().GetEXIFMetaData(image)); } } catch { } PhotoItem.LastTime = xUserTime.UtcTime(); PhotoItem.LastIP = WebHelper.UserHost; PhotoItem.LastUser = UserInfo.UserID; //将文件存储的路径整理好 String fileName = System.IO.Path.GetFileName(FileSystemUtils.HandleFileName(file.FileName)).Replace("." + PhotoItem.FileExtension, ""); //文件名称 String WebPath = String.Format("LayerGallery/uploads/{0}/{1}/{2}/", xUserTime.UtcTime().Year, xUserTime.UtcTime().Month, xUserTime.UtcTime().Day); //检测文件存储路径是否有相关的文件 FileInfo fInfo = new FileInfo(HttpContext.Current.Server.MapPath(String.Format("{0}{1}{2}.{3}", PortalSettings.HomeDirectory, WebPath, fileName, PhotoItem.FileExtension))); //检测文件夹是否存在 if (!System.IO.Directory.Exists(fInfo.Directory.FullName)) { System.IO.Directory.CreateDirectory(fInfo.Directory.FullName); } else { Int32 j = 1; while (fInfo.Exists) { //文件已经存在了 fileName = String.Format("{0}_{1}", FileSystemUtils.HandleFileName(PhotoItem.Name), j); fInfo = new FileInfo(HttpContext.Current.Server.MapPath(String.Format("{0}{1}{2}.{3}", PortalSettings.HomeDirectory, WebPath, fileName, PhotoItem.FileExtension))); j++; } } PhotoItem.FilePath = String.Format("{0}{1}.{2}", WebPath, fileName, PhotoItem.FileExtension); PhotoItem.FileName = String.Format("{0}.{1}", fileName, PhotoItem.FileExtension); try { if (!fInfo.Directory.Exists) { fInfo.Directory.Create(); // FileSystemUtils.AddFolder(PortalSettings, String.Format("{0}DNNGo_PhotoAlbums/{0}/{1}/"), String.Format("{0}DNNGo_PhotoAlbums/{0}/{1}/"), (int)DotNetNuke.Services.FileSystem.FolderController.StorageLocationTypes.InsecureFileSystem); } //构造指定存储路径 file.SaveAs(fInfo.FullName); //FileSystemUtils.AddFile(PhotoItem.FileName, PhotoItem.PortalId, String.Format("DNNGo_PhotoAlbums\\{0}\\{1}\\", PhotoItem.ModuleId, PhotoItem.AlbumID), PortalSettings.HomeDirectoryMapPath, PhotoItem.FileMeta); } catch (Exception ex) { } //给上传的相片设置初始的顺序 QueryParam qp = new QueryParam(); qp.ReturnFields = qp.Orderfld = DNNGo_LayerGallery_Files._.Sort; qp.OrderType = 1; qp.Where.Add(new SearchParam(DNNGo_LayerGallery_Files._.PortalId, PhotoItem.PortalId, SearchType.Equal)); PhotoItem.Sort = Convert.ToInt32(DNNGo_LayerGallery_Files.FindScalar(qp)) + 2; Int32 PhotoId = PhotoItem.Insert(); statuses.Add(new Resource_FilesStatus(PhotoItem, PortalSettings, ModulePath)); } } }