protected void RadImageEditor1_ImageSaving(object sender, ImageEditorSavingEventArgs e)
        {
            System.Drawing.Image modifiedImage = e.Image.Image;
            string strName = e.FileName;
            string strFormat = "image/unknown";
            long imageLength;

            var imgguid = modifiedImage.RawFormat.Guid;
            foreach (ImageCodecInfo codec in ImageCodecInfo.GetImageDecoders())
            {
                if (codec.FormatID == imgguid)
                {
                    strFormat = codec.MimeType;
                    break;
                }
            }

            //get parameters
            if (this.Request.QueryString["File"] != null)
            {
                _FileID = Int32.Parse(this.Request.QueryString["File"]);
            }

            if (this.Request.QueryString["Parent"] != null)
            {
                _ParentID = Int32.Parse(this.Request.QueryString["Parent"]);
            }

            //get current/root file
            DNNQuickApps.Modules.QuickDocsPro.FileController objQuickFiles = new DNNQuickApps.Modules.QuickDocsPro.FileController();
            File objOriginalFile = objQuickFiles.Get(_FileID);
            objOriginalFile.LastModifiedDate = System.DateTime.Now;
            objOriginalFile.LastModifiedByUserID = UserId;

            if (UserId != -1)
            {
                objOriginalFile.LastModifiedByUserName = UserInfo.DisplayName;
            }
            else
            {
                objOriginalFile.LastModifiedByUserName = "******";
            }

            //increment version number
            objOriginalFile.VersionNumber = objOriginalFile.VersionNumber + 1;
            //objOriginalFile.AttachmentName = fileUpload.FileName;

            //create file version and copy attributes from current version
            DNNQuickApps.Modules.QuickDocsPro.File objFile = new DNNQuickApps.Modules.QuickDocsPro.File();
            if ((string)Settings["IsSearchable"] != null)
            {
                if (!Convert.ToBoolean(Settings["IsSearchable"].ToString()))
                {
                    objFile.ModuleID = ModuleId;
                }
            }
            objFile.PortalID = PortalId;
            objFile.Name = strName;
            objFile.CreatedByUserID = objOriginalFile.LastModifiedByUserID;
            objFile.CreatedDate = objOriginalFile.LastModifiedDate;
            objFile.CreatedByUserName = objOriginalFile.LastModifiedByUserName;
            objFile.LastModifiedDate = objOriginalFile.LastModifiedDate;
            objFile.LastModifiedByUserID = objOriginalFile.LastModifiedByUserID;
            objFile.LastModifiedByUserName = objOriginalFile.LastModifiedByUserName;
            objFile.VersionsToKeep = -1;
            objFile.VersionNumber = objOriginalFile.VersionNumber;
            objFile.ItemType = objOriginalFile.ItemType;
            objFile.HomeFolderUserID = objOriginalFile.HomeFolderUserID;
            objFile.RoleID = objOriginalFile.RoleID;

            //Set parent to root/current file
            objFile.ParentID = _FileID;

            objQuickFiles.Update(objOriginalFile);
            objQuickFiles.Create(objFile);

            //upload file version
            FileConfigurationController configCtrl = new FileConfigurationController();
            List<FileConfiguration> configs = configCtrl.GetItems(PortalId) as List<FileConfiguration>;

            if (configs[0].StorageType == "UNC")
            {
                objFile.CreatePath(configs[0].FilesLocation);
                string strPath = configs[0].FilesLocation + objFile.GetFullPath();
                e.Image.Image.Save(strPath);
                //fileUpload.SaveAs(configs[0].FilesLocation + objFile.GetFullPath());
                imageLength = new System.IO.FileInfo(strPath).Length;
            }
            else
            {
                objFile.CreatePath(Server.MapPath(configs[0].FilesLocation));
                string strPath = configs[0].FilesLocation + objFile.GetFullPath();
                e.Image.Image.Save(Server.MapPath(strPath));
                //fileUpload.SaveAs(Server.MapPath(configs[0].FilesLocation) + objFile.GetFullPath());
                imageLength = new System.IO.FileInfo(Server.MapPath(strPath)).Length;

            }

            List<string> fileNameAndExtension = objFile.GetFileNameAndExtension(objOriginalFile.Name);//fileUpload.FileName);

            objFile.AttachmentPath = objFile.GetFullPath();
            objFile.FileType = strFormat; // fileUpload.PostedFile.ContentType;
            objFile.FileLength = (int)imageLength; //fileUpload.PostedFile.ContentLength;
            objFile.Name = strName;//fileNameAndExtension[0];
            objFile.Extension = objOriginalFile.Extension;// fileNameAndExtension[1];
            objFile.AttachmentName = String.Format("{0}.{1}", objFile.Name, objFile.Extension); //.AttachmentName; // fileUpload.FileName;

            objOriginalFile.AttachmentPath = objFile.GetFullPath();
            objOriginalFile.FileType = strFormat; //fileUpload.PostedFile.ContentType;
            objOriginalFile.FileLength = (int)imageLength;//fileUpload.PostedFile.ContentLength;

            //Don't change file name or extension when uploading new image version, only version gets new file name
            //objOriginalFile.Name = fileNameAndExtension[0];
            //objOriginalFile.Extension = fileNameAndExtension[1];

            objQuickFiles.Update(objOriginalFile);
            objQuickFiles.Update(objFile);

            //this.Response.RedirectLocation = Globals.NavigateURL(this.TabId, "", "Folder=" + _ParentID.ToString(), "ModuleID=" + ModuleId, "View=" + _view, "UserID=" + _userIDParameter, "GroupID=" + _roleIDParameter);

            DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, "New version saved successfully.", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.GreenSuccess);

            e.Cancel = true;
        }
        protected void lbnOK_Click(object sender, EventArgs e)
        {
            try
            {

                //check file type first
                //if (fileUpload.HasFile)
                //{
                //    string strAllowedFiles = DotNetNuke.Entities.Controllers.HostController.Instance.GetString("FileExtensions");
                //    string[] strSearchPatterns = strAllowedFiles.Split(',');
                //    string uploadType = fileUpload.PostedFile.FileName.Substring(fileUpload.PostedFile.FileName.LastIndexOf('.')+1);
                //    if (!strAllowedFiles.Contains(uploadType))
                //    {
                //        DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, "File type not allowed", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError);
                //        return;
                //    }
                //}

                //create file
                DNNQuickApps.Modules.QuickDocsPro.FileController objQuickFiles = new DNNQuickApps.Modules.QuickDocsPro.FileController();
                DNNQuickApps.Modules.QuickDocsPro.File objFile = new DNNQuickApps.Modules.QuickDocsPro.File();
                //if (!Convert.ToBoolean(Settings["IsSearchable"].ToString()))
                //{
                //    objFile.ModuleID = ModuleId;
                //}
                objFile.PortalID = PortalId;
                objFile.CreatedByUserID = UserId;
                objFile.CreatedDate = System.DateTime.Now;
                objFile.LastModifiedDate = System.DateTime.Now;
                objFile.LastModifiedByUserID = UserId;
                objFile.VersionsToKeep = -1;
                objFile.VersionNumber = 1;

                //check files type (shared, user, groups)
                String strFilesModuleType = Settings["FilesMode"].ToString();
                if (strFilesModuleType == "UserFiles" || strFilesModuleType == "GroupFiles")
                {
                    if (strFilesModuleType == "UserFiles")
                    {
                        //get UserID parameter
                        if (this.Request.QueryString["UserID"] != null)
                        {
                            _userIDParameter = Convert.ToInt32(this.Request.QueryString["UserID"]);
                        }
                        objFile.HomeFolderUserID = _userIDParameter;
                    }
                    else //group files
                    {
                        //get UserID parameter
                        if (this.Request.QueryString["GroupID"] != null)
                        {
                            _roleIDParameter = Convert.ToInt32(this.Request.QueryString["GroupID"]);
                        }
                        objFile.RoleID = _roleIDParameter;
                    }
                }

                if (UserId != -1)
                {
                    objFile.CreatedByUserName = UserInfo.DisplayName;
                    objFile.LastModifiedByUserName = UserInfo.DisplayName;
                }
                else
                {
                    objFile.CreatedByUserName = "******";
                    objFile.LastModifiedByUserName = "******";
                }

                //create file or folder
                if (this.Request.QueryString["Type"] != null)
                {
                    ItemType = Convert.ToInt32(this.Request.QueryString["Type"]);
                }

                if (ItemType == 1)//File
                {
                    //check file exists
                    if (asyncFileUpload.UploadedFiles.Count == 0)
                    {
                        DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, "Please select a valid file to upload", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError);
                        return;
                    }

                    objFile.Name = "File Upload";
                    objFile.ItemType = 1;
                }
                else if (ItemType == 0) //folder
                {
                    objFile.Name = txtName.Text;
                    objFile.ItemType = 0;
                    objFile.IsFolder = true;
                }
                else if (ItemType == 2) //Hyperlink
                {
                    objFile.Name = txtName.Text;
                    objFile.ItemType = 2;
                    objFile.LinkURL = txtHyperlink.Text;
                }
                else
                {
                    Response.Redirect(Globals.NavigateURL(), true);
                }

                if (this.Request.QueryString["Parent"] != null)
                {
                    ParentID = Int32.Parse(this.Request.QueryString["Parent"]);
                }
                objFile.ParentID = ParentID;
                objFile.Description = "";

                //create file

                objQuickFiles.Create(objFile);

                if (ItemType == 1) //file
                {

                    //create file version and copy attributes from current version
                    DNNQuickApps.Modules.QuickDocsPro.File objVersionFile = new DNNQuickApps.Modules.QuickDocsPro.File();
                    //if (!Convert.ToBoolean(Settings["IsSearchable"].ToString()))
                    //{
                    //    objVersionFile.ModuleID = ModuleId;
                    //}
                    objVersionFile.PortalID = PortalId;
                    objVersionFile.CreatedByUserID = objFile.CreatedByUserID;
                    objVersionFile.CreatedDate = objFile.LastModifiedDate;
                    objVersionFile.CreatedByUserName = objFile.CreatedByUserName;
                    objVersionFile.LastModifiedDate = objFile.LastModifiedDate;
                    objVersionFile.LastModifiedByUserID = objFile.LastModifiedByUserID;
                    objVersionFile.LastModifiedByUserName = objFile.LastModifiedByUserName;
                    objVersionFile.LinkURL = objFile.LinkURL;
                    objVersionFile.ItemType = objFile.ItemType;
                    objVersionFile.VersionsToKeep = -1;
                    objVersionFile.VersionNumber = objFile.VersionNumber;
                    objVersionFile.ParentID = objFile.ID;
                    objVersionFile.Name = "Version Upload";
                    objVersionFile.Description = objFile.Description;
                    objVersionFile.HomeFolderUserID = objFile.HomeFolderUserID;
                    objVersionFile.RoleID = objFile.RoleID;

                    objQuickFiles.Create(objVersionFile);

                    //upload file version
                    FileConfigurationController configCtrl = new FileConfigurationController();
                    List<FileConfiguration> configs = configCtrl.GetItems(PortalId) as List<FileConfiguration>;

                    if (configs[0].StorageType == "UNC")
                    {
                        objVersionFile.CreatePath(configs[0].FilesLocation);
                        //fileUpload.SaveAs(configs[0].FilesLocation + objVersionFile.GetFullPath());
                        asyncFileUpload.UploadedFiles[0].SaveAs(configs[0].FilesLocation + objVersionFile.GetFullPath());
                    }
                    else
                    {
                        objVersionFile.CreatePath(Server.MapPath(configs[0].FilesLocation));
                        //fileUpload.SaveAs(Server.MapPath(configs[0].FilesLocation) + objVersionFile.GetFullPath());
                        asyncFileUpload.UploadedFiles[0].SaveAs(Server.MapPath(configs[0].FilesLocation) + objVersionFile.GetFullPath());
                    }

                    //List<string> fileNameAndExtension = objVersionFile.GetFileNameAndExtension(fileUpload.FileName);
                    List<string> fileNameAndExtension = objVersionFile.GetFileNameAndExtension(asyncFileUpload.UploadedFiles[0].FileName);

                    objVersionFile.AttachmentName = asyncFileUpload.UploadedFiles[0].FileName;// fileUpload.FileName;
                    objVersionFile.AttachmentPath = objVersionFile.GetFullPath();
                    objVersionFile.FileType = asyncFileUpload.UploadedFiles[0].ContentType;// fileUpload.PostedFile.ContentType;
                    objVersionFile.FileLength = (int)asyncFileUpload.UploadedFiles[0].ContentLength;// fileUpload.PostedFile.ContentLength;
                    objVersionFile.Name = fileNameAndExtension[0];
                    objVersionFile.Extension = fileNameAndExtension[1];

                    objFile.AttachmentPath = objVersionFile.GetFullPath();
                    objFile.FileType = asyncFileUpload.UploadedFiles[0].ContentType;// fileUpload.PostedFile.ContentType;
                    objFile.FileLength = (int)asyncFileUpload.UploadedFiles[0].ContentLength;// fileUpload.PostedFile.ContentLength;
                    objFile.Name = fileNameAndExtension[0];
                    objFile.Extension = fileNameAndExtension[1];

                    objQuickFiles.Update(objVersionFile);
                    objQuickFiles.Update(objFile);
                }

                    //create permissions
                    PermissionController objQuickPermissions = new PermissionController();

                    foreach (GridViewRow row in gridPermissions.Rows)
                    {
                        if ((((CheckBox)row.FindControl("chkCanSee")).Checked))
                        {
                            Permission perm = new Permission();
                            perm.CanSee = true;
                            perm.CanAddFiles = ((CheckBox)row.FindControl("chkCanAddFolders")).Checked;
                            perm.CanAddFolders = ((CheckBox)row.FindControl("chkCanAddItems")).Checked;
                            perm.CanModify = ((CheckBox)row.FindControl("chkCanModify")).Checked;
                            perm.CanDelete = ((CheckBox)row.FindControl("chkCanDelete")).Checked;
                            perm.CanModifyPermission = ((CheckBox)row.FindControl("chkCanModifyPermission")).Checked;
                            perm.FileID = objFile.ID;

                            int userID = Int32.Parse(row.Cells[8].Text);
                            int roleID = Int32.Parse(row.Cells[10].Text);
                            string userName = row.Cells[9].Text;
                            string roleName = row.Cells[11].Text;

                            if (userID > 0)
                            {
                                perm.UserID = userID;
                                perm.UserName = userName;
                            }

                            if (roleID > 0)
                            {
                                perm.RoleID = roleID;
                                perm.RoleName = roleName;
                            }

                            objQuickPermissions.Create(perm);
                        }
                    }

                //refresh cac
                SynchronizeModule();

                //Redirect back to the parent folder page
                //Redirect back to the portal home page

                string strItemType = "Folder";
                switch (ItemType)
                {
                    case 0:
                        strItemType = "Folder";
                        break;
                    case 1:
                        strItemType = "File";
                        break;
                    case 2:
                        strItemType = "Hyperlink";
                        break;
                }

                #region "Audit"
                //Audit: Create Item
                AuditController ctrlAudit = new AuditController();
                Audit createAudit = new Audit() { EventDate = objFile.CreatedDate, EventDetails = "File name: " + objFile.Name, EventName = "Created", FileID = objFile.ID, UserID = UserId };
                ctrlAudit.Create(createAudit);
                #endregion

                string successMessage = String.Format("Success=New {0} '{1}' created.", strItemType, objFile.Name);

                this.Response.Redirect(Globals.NavigateURL(this.TabId, "", "Folder=" + objFile.ParentID, "ModuleID=" + ModuleId.ToString(), "UserID=" + _userIDParameter, "GroupID=" + _roleIDParameter, successMessage), true);

            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
        protected void lbnOK_Click(object sender, EventArgs e)
        {
            try
            {
                //check file exists
                if (asyncFileUpload.UploadedFiles.Count == 0)
                {
                    DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, "Please select a valid file to upload", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError);
                    return;
                }

                //get parameters
                if (this.Request.QueryString["File"] != null)
                {
                    FileID = Int32.Parse(this.Request.QueryString["File"]);
                }

                if (this.Request.QueryString["Parent"] != null)
                {
                    ParentID = Int32.Parse(this.Request.QueryString["Parent"]);
                }

                //get current/root file
                DNNQuickApps.Modules.QuickDocsPro.FileController objQuickFiles = new DNNQuickApps.Modules.QuickDocsPro.FileController();
                File objOriginalFile = objQuickFiles.Get(FileID);
                objOriginalFile.LastModifiedDate = System.DateTime.Now;
                objOriginalFile.LastModifiedByUserID = UserId;

                if (UserId != -1)
                {
                    objOriginalFile.LastModifiedByUserName = UserInfo.DisplayName;
                }
                else
                {
                    objOriginalFile.LastModifiedByUserName = "******";
                }

                //increment version number
                objOriginalFile.VersionNumber = objOriginalFile.VersionNumber + 1;
                objOriginalFile.AttachmentName = asyncFileUpload.UploadedFiles[0].FileName;// fileUpload.FileName;

                //create file version and copy attributes from current version
                DNNQuickApps.Modules.QuickDocsPro.File objFile = new DNNQuickApps.Modules.QuickDocsPro.File();
                //if (!Convert.ToBoolean(Settings["IsSearchable"].ToString()))
                //{
                //    objFile.ModuleID = ModuleId;
                //}
                objFile.PortalID = PortalId;
                objFile.Name = objOriginalFile.Name;
                objFile.CreatedByUserID = objOriginalFile.LastModifiedByUserID;
                objFile.CreatedDate = objOriginalFile.LastModifiedDate;
                objFile.CreatedByUserName = objOriginalFile.LastModifiedByUserName;
                objFile.LastModifiedDate = objOriginalFile.LastModifiedDate;
                objFile.LastModifiedByUserID = objOriginalFile.LastModifiedByUserID;
                objFile.LastModifiedByUserName = objOriginalFile.LastModifiedByUserName;
                objFile.VersionsToKeep = -1;
                objFile.VersionNumber = objOriginalFile.VersionNumber;
                objFile.ItemType = objOriginalFile.ItemType;
                objFile.HomeFolderUserID = objOriginalFile.HomeFolderUserID;
                objFile.RoleID = objOriginalFile.RoleID;

                //Set parent to root/current file
                objFile.ParentID = FileID;

                objQuickFiles.Update(objOriginalFile);
                objQuickFiles.Create(objFile);

                //upload file version
                FileConfigurationController configCtrl = new FileConfigurationController();
                List<FileConfiguration> configs = configCtrl.GetItems(PortalId) as List<FileConfiguration>;

                if (configs[0].StorageType == "UNC")
                {
                    objFile.CreatePath(configs[0].FilesLocation);
                    //fileUpload.SaveAs(configs[0].FilesLocation + objFile.GetFullPath());
                    asyncFileUpload.UploadedFiles[0].SaveAs(configs[0].FilesLocation + objFile.GetFullPath());
                }
                else
                {
                    objFile.CreatePath(Server.MapPath(configs[0].FilesLocation));
                    //fileUpload.SaveAs(Server.MapPath(configs[0].FilesLocation) + objFile.GetFullPath());
                    asyncFileUpload.UploadedFiles[0].SaveAs(Server.MapPath(configs[0].FilesLocation) + objFile.GetFullPath());
                }

                //List<string> fileNameAndExtension = objFile.GetFileNameAndExtension(fileUpload.FileName);
                List<string> fileNameAndExtension = objFile.GetFileNameAndExtension(asyncFileUpload.UploadedFiles[0].FileName);

                objFile.AttachmentName = asyncFileUpload.UploadedFiles[0].FileName;// fileUpload.FileName;
                objFile.AttachmentPath = objFile.GetFullPath();
                objFile.FileType = asyncFileUpload.UploadedFiles[0].ContentType;// fileUpload.PostedFile.ContentType;
                objFile.FileLength = (int)asyncFileUpload.UploadedFiles[0].ContentLength;// fileUpload.PostedFile.ContentLength;
                objFile.Name = fileNameAndExtension[0];
                objFile.Extension = fileNameAndExtension[1];

                objOriginalFile.AttachmentPath = objFile.GetFullPath();
                objOriginalFile.FileType = asyncFileUpload.UploadedFiles[0].ContentType; //fileUpload.PostedFile.ContentType;
                objOriginalFile.FileLength = (int)asyncFileUpload.UploadedFiles[0].ContentLength; //fileUpload.PostedFile.ContentLength;
                //Don't change file name when uploading new version, only version gets new file name
                //objOriginalFile.Name = fileNameAndExtension[0];
                objOriginalFile.Extension = fileNameAndExtension[1];

                objQuickFiles.Update(objOriginalFile);
                objQuickFiles.Update(objFile);

                #region "Audit"
                //Audit: New Version Item
                AuditController ctrlAudit = new AuditController();
                Audit versionAudit = new Audit() { EventDate = objOriginalFile.LastModifiedDate, EventDetails = "File name: " + objFile.Name, EventName = "Added Version", FileID = objOriginalFile.ID, UserID = UserId };
                ctrlAudit.Create(versionAudit);
                #endregion

                //refresh cac
                SynchronizeModule();

                //Redirect back to the portal home page
                this.Response.Redirect(Globals.NavigateURL(this.TabId, "", "Folder=" + ParentID, "ModuleID=" + ModuleId.ToString(), "UserID=" + _userIDParameter, "GroupID=" + _roleIDParameter, "Success=New version uploaded for file: " + objOriginalFile.Name), true);
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }