protected void btnNewFolder_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtNewDirectory.Text.Length > 0)
                {
                    SharedFileFolder folder = new SharedFileFolder();
                    folder.ParentId = CurrentFolderId;
                    folder.ModuleId = ModuleId;
                    Module m = new Module(ModuleId);
                    folder.ModuleGuid = m.ModuleGuid;
                    folder.FolderName = Path.GetFileName(txtNewDirectory.Text);
                    if (folder.Save())
                    {
                        BindData();
                    }
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message;
            }

            upFiles.Update();
        }
        protected void dgFile_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            SiteUser siteUser = SiteUtils.GetCurrentSiteUser();

            if (siteUser == null)
            {
                return;
            }

            try
            {
                GridView grid        = (GridView)sender;
                TextBox  txtEditName = (TextBox)grid.Rows[e.RowIndex].Cells[1].FindControl("txtEditName");
                if (txtEditName.Text.Trim().Length < 1)
                {
                    return;
                }


                string   keys      = grid.DataKeys[e.RowIndex].Value.ToString();
                char[]   separator = { '~' };
                string[] args      = keys.Split(separator);
                string   type      = args[1];

                if (type == "folder")
                {
                    int folderID            = int.Parse(args[0]);
                    SharedFileFolder folder = new SharedFileFolder(this.ModuleId, folderID);
                    folder.FolderName = Path.GetFileName(txtEditName.Text);
                    folder.Save();
                }

                if (type == "file")
                {
                    int        fileID     = int.Parse(args[0]);
                    SharedFile sharedFile = new SharedFile(this.ModuleId, fileID);
                    sharedFile.ContentChanged += new ContentChangedEventHandler(sharedFile_ContentChanged);
                    sharedFile.FriendlyName    = Path.GetFileName(txtEditName.Text);
                    sharedFile.UploadUserId    = siteUser.UserId;
                    sharedFile.UploadDate      = DateTime.UtcNow; //lastModDate
                    sharedFile.Save();
                }

                dgFile.EditIndex = -1;
                BindData();
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message;
            }
            upFiles.Update();
        }
Esempio n. 3
0
        private void btnUpdateFolder_Click(object sender, EventArgs e)
        {
            SharedFileFolder folder = new SharedFileFolder(this.moduleId, this.itemId);

            if ((folder.FolderId > 0) && (folder.ModuleId == this.moduleId))
            {
                folder.FolderName = this.txtFolderName.Text;
                folder.ParentId   = int.Parse(this.ddFolderList.SelectedValue);
                folder.Save();
            }

            CacheHelper.TouchCacheDependencyFile(cacheDependencyKey);
            if (hdnReturnUrl.Value.Length > 0)
            {
                WebUtils.SetupRedirect(this, hdnReturnUrl.Value);
                return;
            }

            WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
        }
        public void InstallContent(Module module, string configInfo)
        {
            if (string.IsNullOrEmpty(configInfo))
            {
                return;
            }

            SiteSettings siteSettings = new SiteSettings(module.SiteId);
            SiteUser     admin        = SiteUser.GetNewestUser(siteSettings);

            string upLoadPath = HostingEnvironment.MapPath("~/Data/Sites/" + module.SiteId.ToInvariantString() + "/SharedFiles/");

            if (!Directory.Exists(upLoadPath))
            {
                Directory.CreateDirectory(upLoadPath);
            }

            XmlDocument xml = new XmlDocument();

            using (StreamReader stream = File.OpenText(HostingEnvironment.MapPath(configInfo)))
            {
                xml.LoadXml(stream.ReadToEnd());
            }

            XmlAttributeCollection attributes = xml.DocumentElement.Attributes;

            if (attributes["filePath"].Value.Length > 0)
            {
                string destPath = "~/Data/Sites/" + module.SiteId.ToInvariantString() + "/SharedFiles/";

                if (!Directory.Exists(HostingEnvironment.MapPath(destPath)))
                {
                    Directory.CreateDirectory(HostingEnvironment.MapPath(destPath));
                }

                IOHelper.CopyFolderContents(HostingEnvironment.MapPath(attributes["filePath"].Value), HostingEnvironment.MapPath(destPath));

                destPath = "~/Data/Sites/" + module.SiteId.ToInvariantString() + "/SharedFiles/History/";

                if (!Directory.Exists(HostingEnvironment.MapPath(destPath)))
                {
                    Directory.CreateDirectory(HostingEnvironment.MapPath(destPath));
                }
            }

            foreach (XmlNode node in xml.DocumentElement.ChildNodes)
            {
                if (node.Name == "file") //root level files
                {
                    CreateFile(module, null, admin, node);
                }
            }

            XmlNode foldersNode = null;

            foreach (XmlNode node in xml.DocumentElement.ChildNodes)
            {
                if (node.Name == "folders")
                {
                    foldersNode = node;
                    break;
                }
            }

            if (foldersNode != null)
            {
                foreach (XmlNode folderNode in foldersNode.ChildNodes)
                {
                    if (folderNode.Name == "folder")
                    {
                        XmlAttributeCollection folderAttributes = folderNode.Attributes;

                        if ((folderAttributes["folderName"] != null) && (folderAttributes["folderName"].Value.Length > 0))
                        {
                            //create folder
                            SharedFileFolder folder = new SharedFileFolder();
                            folder.ModuleId   = module.ModuleId;
                            folder.ModuleGuid = module.ModuleGuid;
                            folder.FolderName = folderAttributes["folderName"].Value;
                            folder.Save();

                            foreach (XmlNode fileNode in folderNode.ChildNodes)
                            {
                                if (fileNode.Name == "file")
                                {
                                    CreateFile(module, folder, admin, fileNode);
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        private void btnUpdateFolder_Click(object sender, EventArgs e)
        {
            SharedFileFolder folder = new SharedFileFolder(moduleId, itemId);

            if ((folder.FolderId > 0) && (folder.ModuleId == moduleId))
            {
                List <ListItem> selectedRoles =
                    cblRolesThatCanViewFolder.Items.Cast <ListItem>()
                    .Where(li => li.Selected)
                    .ToList();

                string viewRoles = String.Join(";", selectedRoles.Select(x => x.Value.ToString()).ToArray());

                folder.ViewRoles = viewRoles;

                if (cbPushRolesToChildren.Checked)
                {
                    // Current Folder's (can be root) Folders and Files
                    FoldersAndFiles foldersAndFiles = SharedFileFolder.GetFoldersAndFilesModel(moduleId, folder.FolderId);

                    // Recursively loop through folders and get child items
                    void getChildItems(List <Folder> folders)
                    {
                        foreach (var childFolder in folders)
                        {
                            FoldersAndFiles childFoldersAndFiles = SharedFileFolder.GetFoldersAndFilesModel(moduleId, childFolder.ID);

                            if (childFoldersAndFiles.Folders != null && childFoldersAndFiles.Folders.Count() > 0)
                            {
                                // Add folders to folders list
                                childFoldersAndFiles.Folders.ForEach(f =>
                                {
                                    foldersAndFiles.Folders.Add(f);
                                });

                                // Recursively call this function again
                                getChildItems(childFoldersAndFiles.Folders);
                            }

                            if (childFoldersAndFiles.Files != null && childFoldersAndFiles.Files.Count() > 0)
                            {
                                // Add files to files list
                                childFoldersAndFiles.Files.ForEach(f =>
                                {
                                    foldersAndFiles.Files.Add(f);
                                });
                            }
                        }
                    }

                    getChildItems(foldersAndFiles.Folders);

                    // Loop through all Folders and set their ViewRoles to the parent folder's
                    foldersAndFiles.Folders.ForEach(f =>
                    {
                        var setFolder = new SharedFileFolder
                        {
                            FolderId   = f.ID,
                            ModuleId   = f.ModuleID,
                            FolderName = f.Name,
                            ParentId   = f.ParentID,
                            ModuleGuid = f.ModuleGuid,
                            ParentGuid = f.ParentGuid,
                            ViewRoles  = folder.ViewRoles
                        };

                        setFolder.Save();
                    });

                    // Loop through all Files and set their ViewRoles to the parent folder's
                    foldersAndFiles.Files.ForEach(f =>
                    {
                        var setFile = new SharedFile
                        {
                            ItemId           = f.ID,
                            ModuleId         = f.ModuleID,
                            UploadUserId     = f.UploadUserID,
                            FriendlyName     = f.Name,
                            OriginalFileName = f.OriginalFileName,
                            ServerFileName   = f.ServerFileName,
                            SizeInKB         = f.SizeInKB,
                            UploadDate       = f.UploadDate,
                            FolderId         = f.FolderID,
                            ModuleGuid       = f.ModuleGuid,
                            UserGuid         = f.UserGuid,
                            FolderGuid       = f.FolderGuid,
                            Description      = f.Description,
                            ViewRoles        = folder.ViewRoles
                        };

                        setFile.Save();
                    });

                    // 1. Get all files for current folder
                    // 2. get all folders for current folder (sql should only get folders which contain files or folders)
                    // 3. set viewroles on each file/folder in current folder
                    // 4. step through all folders in current folder and repeat steps 1-3

                    // SQL Method?
                    // 1. update all files with parentid = current folder id and moduleid = moduleid
                    // 2. update all folders with parent id = current folder id and moduleid = moduleid
                    // 3. update all files/folders within each folder
                }

                folder.FolderName = txtFolderName.Text;
                folder.ParentId   = int.Parse(ddFolderList.SelectedValue);
                folder.Save();
            }

            CacheHelper.ClearModuleCache(moduleId);

            if (hdnReturnUrl.Value.Length > 0)
            {
                WebUtils.SetupRedirect(this, hdnReturnUrl.Value);

                return;
            }

            WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
        }