Example #1
0
        private void btnUpdateFile_Click(object sender, EventArgs e)
        {
            SiteUser siteUser = SiteUtils.GetCurrentSiteUser();

            if (siteUser == null)
            {
                return;
            }

            SharedFile file = new SharedFile(moduleId, itemId);

            file.ContentChanged += new ContentChangedEventHandler(sharedFile_ContentChanged);

            if ((file.ItemId > 0) && (file.ModuleId == moduleId))
            {
                file.FriendlyName = txtFriendlyName.Text;
                file.Description  = edDescription.Text;
                file.FolderId     = int.Parse(ddFolders.SelectedValue);

                if (file.FolderId > -1)
                {
                    SharedFileFolder folder = new SharedFileFolder(moduleId, file.FolderId);
                    file.FolderGuid = folder.FolderGuid;
                }

                if (file.ModuleGuid == Guid.Empty)
                {
                    Module m = new Module(moduleId);
                    file.ModuleGuid = m.ModuleGuid;
                }

                file.UploadUserId = siteUser.UserId;
                // really last mod date
                file.UploadDate = DateTime.UtcNow;

                List <ListItem> selectedRoles = cblRolesThatCanViewFile.Items.Cast <ListItem>()
                                                .Where(li => li.Selected)
                                                .ToList();

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

                file.ViewRoles = viewRoles;
                file.Save();
            }

            CurrentPage.UpdateLastModifiedTime();
            CacheHelper.ClearModuleCache(moduleId);
            SiteUtils.QueueIndexing();

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

                return;
            }

            WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
        }
Example #2
0
        private void Run()
        {
            NetworkStream strm    = null;
            String        choosen = null;

            do
            {
                try
                {
                    strm = client.GetStream();
                    IFormatter formatter = new BinaryFormatter();
                    choosen = (String)formatter.Deserialize(strm);

                    switch (choosen)
                    {
                    case "1":
                        Console.WriteLine(choosen);
                        formatter.Serialize(strm, findAllStoredFiles());
                        break;

                    case "2":
                        Console.WriteLine(choosen);
                        try
                        {
                            String path = (String)formatter.Deserialize(strm);
                            Console.WriteLine(path);
                            SharedFile file = new SharedFile(path);

                            formatter.Serialize(strm, file);
                        }
                        catch (SerializationException se)
                        {
                            Console.WriteLine("Serialization exception" + se.Message);
                        }
                        break;

                    case "3":
                        Console.WriteLine(choosen);
                        try {
                            SharedFile upload = (SharedFile)formatter.Deserialize(strm);
                            upload.Save("stored");
                        }
                        catch (SerializationException se)
                        {
                            Console.WriteLine("Deserialization exception" + se.Message);
                        }

                        break;
                    }
                }
                catch (Exception e)
                {
                    strm.Close();
                    Console.WriteLine(e.Message);
                    break;
                }
            } while (!choosen.Equals("4"));
        }
Example #3
0
        private void btnUpload_Click(object sender, EventArgs e)
        {
            if (uploader.HasFile)
            {
                SiteUser siteUser = SiteUtils.GetCurrentSiteUser();
                if (siteUser == null)
                {
                    return;
                }

                SharedFile sharedFile = new SharedFile(this.moduleId, this.itemId);
                sharedFile.ContentChanged += new ContentChangedEventHandler(sharedFile_ContentChanged);

                if (config.EnableVersioning)
                {
                    bool historyCreated = SharedFilesHelper.CreateHistory(sharedFile, fileSystem, virtualSourcePath, virtualHistoryPath);
                    if (historyCreated)
                    {
                        sharedFile.ServerFileName = System.Guid.NewGuid().ToString() + ".config";
                    }
                }


                sharedFile.ModuleId = this.moduleId;
                if (sharedFile.ModuleGuid == Guid.Empty)
                {
                    Module m = GetModule(moduleId, SharedFile.FeatureGuid);
                    sharedFile.ModuleGuid = m.ModuleGuid;
                }

                string fileName = Path.GetFileName(uploader.FileName);

                sharedFile.OriginalFileName = fileName;
                sharedFile.FriendlyName     = fileName;
                sharedFile.SizeInKB         = (int)(uploader.FileBytes.Length / 1024);
                sharedFile.UploadUserId     = siteUser.UserId;
                sharedFile.UploadDate       = DateTime.UtcNow;

                if (sharedFile.Save())
                {
                    string destPath = virtualSourcePath + sharedFile.ServerFileName;

                    using (Stream s = uploader.FileContent)
                    {
                        //fileSystem.SaveFile(destPath, file1.FileContent, file1.ContentType, true);
                        fileSystem.SaveFile(destPath, s, IOHelper.GetMimeType(Path.GetExtension(sharedFile.FriendlyName).ToLower()), true);
                    }
                }



                CurrentPage.UpdateLastModifiedTime();
                CacheHelper.ClearModuleCache(moduleId);
                SiteUtils.QueueIndexing();
            }

            WebUtils.SetupRedirect(this, Request.RawUrl);
        }
Example #4
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            // as long as javascript is available this code should never execute
            // because the standard file input ir replaced by javascript and the file upload happens
            // at the service url /SharedFiles/upload.ashx
            // this is fallback implementation

            if (!fileSystem.FolderExists(fileVirtualBasePath))
            {
                fileSystem.CreateFolder(fileVirtualBasePath);
            }

            SiteUser siteUser = SiteUtils.GetCurrentSiteUser();

            if (siteUser == null)
            {
                WebUtils.SetupRedirect(this, Request.RawUrl); return;
            }


            if (uploader.HasFile)
            {
                SharedFile sharedFile = new SharedFile();

                string fileName = Path.GetFileName(uploader.FileName);

                sharedFile.ModuleId         = ModuleId;
                sharedFile.ModuleGuid       = ModuleConfiguration.ModuleGuid;
                sharedFile.OriginalFileName = fileName;
                sharedFile.FriendlyName     = fileName;
                sharedFile.SizeInKB         = (int)(uploader.FileContent.Length / 1024);
                sharedFile.FolderId         = CurrentFolderId;

                if (CurrentFolderId > -1)
                {
                    SharedFileFolder folder = new SharedFileFolder(ModuleId, CurrentFolderId);
                    sharedFile.FolderGuid = folder.FolderGuid;
                }

                sharedFile.UploadUserId = siteUser.UserId;
                sharedFile.UserGuid     = siteUser.UserGuid;

                sharedFile.ContentChanged += new ContentChangedEventHandler(SharedFile_ContentChanged);

                if (sharedFile.Save())
                {
                    string destPath = VirtualPathUtility.Combine(fileVirtualBasePath, sharedFile.ServerFileName);

                    using (Stream s = uploader.FileContent)
                    {
                        fileSystem.SaveFile(destPath, s, IOHelper.GetMimeType(Path.GetExtension(sharedFile.FriendlyName).ToLower()), true);
                    }
                }
            }

            WebUtils.SetupRedirect(this, Request.RawUrl);
        }
        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();
        }
Example #6
0
        private void btnUpload_Click(object sender, EventArgs e)
        {
            SiteUser siteUser = SiteUtils.GetCurrentSiteUser();

            if (siteUser == null)
            {
                return;
            }

            SharedFile sharedFile = new SharedFile(this.moduleId, this.itemId);

            sharedFile.ContentChanged += new ContentChangedEventHandler(sharedFile_ContentChanged);
            if ((sharedFile.ItemId > 0) && (sharedFile.ModuleId == this.moduleId))
            {
                if (file1.HasFile && file1.FileName != null && file1.FileName.Trim().Length > 0)
                {
                    //SharedFile sharedFile = new SharedFile();
                    sharedFile.CreateHistory(upLoadPath, historyPath);
                    sharedFile.ModuleId = this.moduleId;
                    if (sharedFile.ModuleGuid == Guid.Empty)
                    {
                        Module m = new Module(moduleId);
                        sharedFile.ModuleGuid = m.ModuleGuid;
                    }
                    sharedFile.OriginalFileName = file1.FileName;
                    // FIXME: the following line probably doesn't work right when uploading from
                    // Windows to Unix because GetFileName will be looking for "\" and the FileName
                    // will contain "/".
                    sharedFile.FriendlyName = Path.GetFileName(file1.FileName);
                    sharedFile.SizeInKB     = (int)(file1.ContentLength / 1024);

                    //sharedFile.FolderID = this.CurrentFolderID;
                    sharedFile.UploadUserId = siteUser.UserId;

                    if (sharedFile.Save())
                    {
                        string destPath = upLoadPath + sharedFile.ServerFileName;
                        if (File.Exists(destPath))
                        {
                            File.Delete(destPath);
                        }
                        file1.MoveTo(destPath, MoveToOptions.Overwrite);
                    }
                }

                CurrentPage.UpdateLastModifiedTime();
                CacheHelper.TouchCacheDependencyFile(cacheDependencyKey);
                SiteUtils.QueueIndexing();
                WebUtils.SetupRedirect(this, Request.RawUrl);
            }
        }
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            string upLoadPath = Page.Server.MapPath(WebUtils.GetApplicationRoot() + "/Data/Sites/"
                                                    + SiteId.ToString(CultureInfo.InvariantCulture) + "/SharedFiles/");

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

            SiteUser siteUser = SiteUtils.GetCurrentSiteUser();

            if (multiFile.Files.Length > 0)
            {
                foreach (UploadedFile file in multiFile.Files)
                {
                    if (file != null && file.FileName != null && file.FileName.Trim().Length > 0)
                    {
                        SharedFile sharedFile = new SharedFile();
                        Module     m          = new Module(ModuleId);

                        sharedFile.ModuleId         = ModuleId;
                        sharedFile.ModuleGuid       = m.ModuleGuid;
                        sharedFile.OriginalFileName = file.FileName;
                        sharedFile.FriendlyName     = Path.GetFileName(file.FileName);
                        sharedFile.SizeInKB         = (int)(file.ContentLength / 1024);
                        sharedFile.FolderId         = CurrentFolderId;
                        if (CurrentFolderId > -1)
                        {
                            SharedFileFolder folder = new SharedFileFolder(ModuleId, CurrentFolderId);
                            sharedFile.FolderGuid = folder.FolderGuid;
                        }
                        sharedFile.UploadUserId    = siteUser.UserId;
                        sharedFile.UserGuid        = siteUser.UserGuid;
                        sharedFile.ContentChanged += new ContentChangedEventHandler(sharedFile_ContentChanged);

                        if (sharedFile.Save())
                        {
                            string destPath = Path.Combine(upLoadPath, sharedFile.ServerFileName);
                            if (File.Exists(destPath))
                            {
                                File.Delete(destPath);
                            }
                            file.MoveTo(destPath, MoveToOptions.Overwrite);
                        }
                    }
                }
            }

            WebUtils.SetupRedirect(this, Request.RawUrl);
        }
        private void button2_Click(object sender, EventArgs e)
        {
            String item = null;

            try {
                item = listBox1.SelectedItem.ToString();
                formatter.Serialize(strm, "2");
                SharedFile downloaded = null;
                try
                {
                    formatter.Serialize(strm, item);
                }
                catch (Exception exception)
                {
                    MessageBox.Show("Somethings goes wrong, " + exception.Message);
                }
                finally
                {
                    downloaded = (SharedFile)formatter.Deserialize(strm);
                }
                MessageBox.Show("File downloaded");
                DialogResult result1 = MessageBox.Show("Do you want to save file?",
                                                       "File saving",
                                                       MessageBoxButtons.YesNo);
                if (result1 == DialogResult.Yes)
                {
                    using (var folderDialog = new FolderBrowserDialog())
                    {
                        if (folderDialog.ShowDialog() == DialogResult.OK)
                        {
                            if (downloaded != null)
                            {
                                downloaded.Save(folderDialog.SelectedPath);
                                MessageBox.Show("File saved");
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("File not saved");
                }
            }
            catch (NullReferenceException nullException)
            {
                MessageBox.Show("Please select item you want to download");
            }
        }
        private void CreateFile(Module module, SharedFileFolder folder, SiteUser siteUser, XmlNode fileNode)
        {
            SharedFile sharedFile = new SharedFile();

            sharedFile.ModuleId   = module.ModuleId;
            sharedFile.ModuleGuid = module.ModuleGuid;
            if (folder != null)
            {
                sharedFile.FolderId   = folder.FolderId;
                sharedFile.FolderGuid = folder.FolderGuid;
            }

            if (siteUser != null)
            {
                sharedFile.UploadUserId = siteUser.UserId;
                sharedFile.UserGuid     = siteUser.UserGuid;
            }

            XmlAttributeCollection fileAttributes = fileNode.Attributes;

            if (fileAttributes["originalFileName"] != null)
            {
                sharedFile.OriginalFileName = fileAttributes["originalFileName"].Value;
            }

            if (fileAttributes["friendlyName"] != null)
            {
                sharedFile.FriendlyName = fileAttributes["friendlyName"].Value;
            }

            if (fileAttributes["serverFileName"] != null)
            {
                sharedFile.ServerFileName = fileAttributes["serverFileName"].Value;
            }

            if (fileAttributes["sortOrder"] != null)
            {
                int size = 0;
                if (int.TryParse(fileAttributes["sortOrder"].Value, out size))
                {
                    sharedFile.SizeInKB = size;
                }
            }

            sharedFile.Save();
        }
Example #10
0
        private void btnUpdateFile_Click(object sender, EventArgs e)
        {
            SiteUser siteUser = SiteUtils.GetCurrentSiteUser();

            if (siteUser == null)
            {
                return;
            }

            SharedFile file = new SharedFile(this.moduleId, this.itemId);

            file.ContentChanged += new ContentChangedEventHandler(sharedFile_ContentChanged);

            if ((file.ItemId > 0) && (file.ModuleId == this.moduleId))
            {
                file.FriendlyName = this.txtFriendlyName.Text;
                file.Description  = edDescription.Text;
                file.FolderId     = int.Parse(this.ddFolders.SelectedValue);
                if (file.FolderId > -1)
                {
                    SharedFileFolder folder = new SharedFileFolder(this.moduleId, file.FolderId);
                    file.FolderGuid = folder.FolderGuid;
                }
                if (file.ModuleGuid == Guid.Empty)
                {
                    Module m = new Module(moduleId);
                    file.ModuleGuid = m.ModuleGuid;
                }

                file.UploadUserId = siteUser.UserId;
                // really last mod date
                file.UploadDate = DateTime.UtcNow;

                file.Save();
            }
            CurrentPage.UpdateLastModifiedTime();
            CacheHelper.ClearModuleCache(moduleId);
            SiteUtils.QueueIndexing();
            if (hdnReturnUrl.Value.Length > 0)
            {
                WebUtils.SetupRedirect(this, hdnReturnUrl.Value);
                return;
            }

            WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
        }
Example #11
0
        public static bool RestoreHistoryFile(
            int historyId,
            IFileSystem fileSystem,
            string virtualSourcePath,
            string virtualHistoryPath)
        {
            bool historyRestored = false;

            if (string.IsNullOrEmpty(virtualSourcePath))
            {
                return(historyRestored);
            }
            if (string.IsNullOrEmpty(virtualHistoryPath))
            {
                return(historyRestored);
            }
            if (fileSystem == null)
            {
                return(historyRestored);
            }


            int      itemId              = 0;
            int      moduleId            = 0;
            string   historyFriendlyName = string.Empty;
            string   historyOriginalName = string.Empty;
            string   historyServerName   = string.Empty;
            DateTime historyUploadDate   = DateTime.Now;
            int      historyUploadUserID = 0;
            int      historyFileSize     = 0;

            using (IDataReader reader = SharedFile.GetHistoryFileAsIDataReader(historyId))
            {
                if (reader.Read())
                {
                    itemId              = Convert.ToInt32(reader["ItemID"]);
                    moduleId            = Convert.ToInt32(reader["ModuleID"]);
                    historyFriendlyName = reader["FriendlyName"].ToString();
                    historyOriginalName = reader["OriginalFileName"].ToString();
                    historyServerName   = reader["ServerFileName"].ToString();
                    historyFileSize     = Convert.ToInt32(reader["SizeInKB"]);
                    historyUploadUserID = Convert.ToInt32(reader["UploadUserID"]);
                    historyUploadDate   = DateTime.Parse(reader["UploadDate"].ToString());
                }
            }

            SharedFile sharedFile = new SharedFile(moduleId, itemId);

            CreateHistory(sharedFile, fileSystem, virtualSourcePath, virtualHistoryPath);

            //File.Move(Path.Combine(historyPath, Path.GetFileName(historyServerName)), Path.Combine(sourcePath, Path.GetFileName(historyServerName)));
            fileSystem.MoveFile(
                VirtualPathUtility.Combine(virtualHistoryPath, historyServerName),
                VirtualPathUtility.Combine(virtualSourcePath, historyServerName),
                true);

            sharedFile.ServerFileName   = historyServerName;
            sharedFile.OriginalFileName = historyOriginalName;
            sharedFile.FriendlyName     = historyFriendlyName;
            sharedFile.SizeInKB         = historyFileSize;
            sharedFile.UploadDate       = historyUploadDate;
            sharedFile.UploadUserId     = historyUploadUserID;
            historyRestored             = sharedFile.Save();
            SharedFile.DeleteHistory(historyId);

            fileSystem.DeleteFile(VirtualPathUtility.Combine(virtualHistoryPath, historyServerName));


            return(historyRestored);
        }
        public static void Run()
        {
            // DO ZROBIENIA
            //SERWER NAJPIERW ODBIERA STATUS OD KLIENTA CO CHCE ZROBIC (1-SCIAGNAC PLIK, 2-WSTAWIC PLIK, 3-LISTA DOSTEPNYCH PLIKOW NA SERWERZE)
            //ODPOWIEDNIE DZIALANIE, ZASTANOWIC SIE NAD LOCKOWANIEM PLIKOW PODCZAS ODCZYTU CZY ZAPISU
            //
            Console.WriteLine("Connecting to server");
            object    locker   = new object();
            String    serverIp = IPAddress.Loopback.ToString();
            TcpClient client   = new TcpClient(serverIp, 5670);

            Console.WriteLine("Connected");
            IFormatter    formatter = new BinaryFormatter();
            NetworkStream strm      = client.GetStream();
            bool          flag      = true;

            while (flag)
            {
                Menu();
                string choosen = Console.ReadLine();
                switch (choosen)
                {
                case "1":
                    formatter.Serialize(strm, choosen);
                    String listOfFiles = (String)formatter.Deserialize(strm);
                    Msg(listOfFiles);
                    break;

                case "2":
                    formatter.Serialize(strm, choosen);
                    Msg("type which file you want to download?:");
                    String     file       = Console.ReadLine();
                    SharedFile downloaded = null;
                    try {
                        formatter.Serialize(strm, file);
                    }
                    catch (Exception e)
                    {
                        Msg(e.Message);
                    }
                    finally
                    {
                        downloaded = (SharedFile)formatter.Deserialize(strm);
                    }
                    Msg("file downloaded");
                    Msg("where you want to save file?:");
                    String savePath = Console.ReadLine();
                    if (downloaded != null)
                    {
                        downloaded.Save(savePath);
                    }
                    Msg("File saved");
                    break;

                case "3":
                    formatter.Serialize(strm, choosen);
                    Msg("type which file you want to send:");
                    String     filePath = Console.ReadLine();
                    SharedFile toUpload = new SharedFile(filePath);
                    formatter.Serialize(strm, toUpload);
                    Msg("File sended");
                    break;

                default:
                    flag = false;
                    strm.Close();
                    client.Close();
                    Environment.Exit(1);
                    break;
                }
            }
        }
Example #13
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());
        }