Esempio n. 1
0
        // Delete file from the server
        private void DeleteFile(HttpContext context)
        {
            Int32 PhotoID = WebHelper.GetIntParam(context.Request, "ID", 0);
            DNNGo_ThemePlugin_Multimedia PhotoItem = DNNGo_ThemePlugin_Multimedia.FindByKeyForEdit(PhotoID);

            if (PhotoItem != null && PhotoItem.ID > 0)
            {
                //要删除实际的文件
                String DeletePath = HttpContext.Current.Server.MapPath(GetPhotoPath(PhotoItem.FilePath));

                //删除分类项
                //DNNGo_ThemePlugin_Articles_Files.DeleteByMultimedia(PhotoItem.ID);

                //删除文件
                if (File.Exists(DeletePath))
                {
                    try
                    {
                        File.Delete(DeletePath);
                    }
                    catch { }
                }
                //删除记录
                PhotoItem.Delete();
            }
        }
Esempio n. 2
0
        private void DeliverFile(HttpContext context)
        {
            DNNGo_ThemePlugin_Multimedia DataItem = DNNGo_ThemePlugin_Multimedia.FindByKeyForEdit(WebHelper.GetStringParam(context.Request, "PhotoID", "0"));

            if (DataItem != null && DataItem.ID > 0)
            {
                String Picture = GetPhotoPath(DataItem);

                if (!String.IsNullOrEmpty(Picture) && File.Exists(context.Server.MapPath(Picture)))
                {
                    context.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + DataItem.FileName + "\"");
                    context.Response.ContentType = "application/octet-stream";
                    context.Response.ClearContent();
                    context.Response.WriteFile(context.Server.MapPath(Picture));
                }
                else
                {
                    context.Response.StatusCode = 404;
                }
            }
            else
            {
                context.Response.StatusCode = 404;
            }



            //var filename = context.Request["PhotoID"];
            //var filePath = StorageRoot + filename;

            //if (File.Exists(filePath)) {
            //    context.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
            //    context.Response.ContentType = "application/octet-stream";
            //    context.Response.ClearContent();
            //    context.Response.WriteFile(filePath);
            //} else
            //    context.Response.StatusCode = 404;
        }
        /// <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_ThemePlugin_Multimedia Multimedia = DNNGo_ThemePlugin_Multimedia.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)
                                {
                                    ////删除媒体与文章关系
                                    //DNNGo_ThemePlugin_Articles_Files.DeleteByMultimedia(Multimedia.ID);
                                    ////更新所属图片为空
                                    //DNNGo_ThemePlugin_Articles.DeleteByMultimedia(Multimedia.ID);

                                    //删除文件
                                    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);
            }
        }
        /// <summary>
        /// 列表上的项删除事件
        /// </summary>
        protected void btnRemove_Click(object sender, EventArgs e)
        {
            try
            {
                LinkButton btnRemove = (LinkButton)sender;

                if (btnRemove != null && !String.IsNullOrEmpty(btnRemove.CommandArgument))
                {
                    mTips.IsPostBack = true;

                    DNNGo_ThemePlugin_Multimedia Multimedia = DNNGo_ThemePlugin_Multimedia.FindByKeyForEdit(btnRemove.CommandArgument);

                    if (Multimedia != null && Multimedia.ID > 0)
                    {
                        //if (Multimedia.Status == (Int32)EnumFileStatus.Recycle)
                        //{
                        //要删除实际的文件
                        String DeletePath = Server.MapPath(GetPhotoPath(Multimedia.FilePath));
                        if (Multimedia.Delete() > 0)
                        {
                            //删除分类项
                            //DNNGo_ThemePlugin_Articles_Files.DeleteByMultimedia(Multimedia.ID);
                            //更新所属图片为空
                            //DNNGo_ThemePlugin_Articles.DeleteByMultimedia(Multimedia.ID);

                            //删除文件
                            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 = (Int32)EnumFileStatus.Recycle;
                        //    if (Multimedia.Update() > 0)
                        //    {
                        //        //移动到回收站操作成功
                        //        mTips.LoadMessage("DeleteCommentSuccess", EnumTips.Success, this, new String[] { Multimedia.FileName });
                        //    }
                        //    else
                        //    {
                        //        //移动到回收站操作失败
                        //        mTips.LoadMessage("DeleteCommentError", EnumTips.Success, this, new String[] { Multimedia.FileName });
                        //    }
                        //}
                        BindDataList();
                    }
                }
            }
            catch (Exception ex)
            {
                ProcessModuleLoadException(ex);
            }
        }
        public void Execute(BasePage Context)
        {
            Dictionary <String, Object> jsonPicture = new Dictionary <String, Object>();

            Int32 MediaID = WebHelper.GetIntParam(Context.Request, "MediaID", 0);

            if (MediaID > 0)
            {
                DNNGo_ThemePlugin_Multimedia PictureItem = DNNGo_ThemePlugin_Multimedia.FindByKeyForEdit(MediaID);
                if (PictureItem != null && PictureItem.ID > 0)
                {
                    jsonPicture.Add("ID", PictureItem.ID);
                    jsonPicture.Add("CreateTime", PictureItem.LastTime);
                    jsonPicture.Add("Name", PictureItem.Name);
                    jsonPicture.Add("Extension", PictureItem.FileExtension);
                    String ThumbnailUrl = Context.ViewLinkUrl(String.Format("MediaID={0}", PictureItem.ID));
                    jsonPicture.Add("ThumbnailUrl", ThumbnailUrl);
                    jsonPicture.Add("FileUrl", Context.GetPhotoPath(PictureItem.FilePath));


                    jsonPicture.Add("Thumbnail", String.Format("<img style=\"border-width:0px; max-height:60px;max-width:80px;\"  src=\"{0}\"  /> ", ThumbnailUrl));

                    //判断当前文件是否为图片
                    if (!String.IsNullOrEmpty(PictureItem.FileExtension) && ("gif,jpg,jpeg,bmp,png").IndexOf(PictureItem.FileExtension, StringComparison.CurrentCultureIgnoreCase) >= 0)
                    {
                        jsonPicture.Add("IsVideo", false);
                        jsonPicture.Add("IsPicture", true);
                    }
                    else if (!String.IsNullOrEmpty(PictureItem.FileExtension) && ("mp4,mkv,avi,ogv,webm,m4v").IndexOf(PictureItem.FileExtension, StringComparison.CurrentCultureIgnoreCase) >= 0)
                    {
                        jsonPicture.Add("IsVideo", true);
                        jsonPicture.Add("IsPicture", false);


                        switch (PictureItem.FileExtension)
                        {
                        case "mp4": jsonPicture.Add("IsMp4", true); break;

                        case "m4v": jsonPicture.Add("IsM4v", true); break;

                        case "ogv": jsonPicture.Add("IsOgv", true); break;

                        case "webm": jsonPicture.Add("IsWebm", true); break;

                        default: break;
                        }
                    }
                    else if (!String.IsNullOrEmpty(PictureItem.FileExtension) && ("flv,swf").IndexOf(PictureItem.FileExtension, StringComparison.CurrentCultureIgnoreCase) >= 0)
                    {
                        jsonPicture.Add("IsFlash", true);
                        jsonPicture.Add("IsPicture", false);
                        jsonPicture.Add("Guid", Guid.NewGuid().ToString());
                    }
                    else
                    {
                        jsonPicture.Add("IsVideo", false);
                        jsonPicture.Add("IsPicture", false);
                    }
                }
            }

            //转换数据为json
            JavaScriptSerializer jsSerializer = new JavaScriptSerializer();

            ResponseString = jsSerializer.Serialize(jsonPicture);
        }