private void DeleteItem(GridViewRow e)
        {
            string keys = dgFile.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.DeleteAllFiles(this.filePath);
                SharedFilesHelper.DeleteAllFiles(folder, fileSystem, fileVirtualBasePath, config);
                SharedFileFolder.DeleteSharedFileFolder(folderID);

                //TODO: file content changed event so re-index

            }

            if(type == "file")
            {
                int fileID = int.Parse(args[0]);
                SharedFile sharedFile = new SharedFile(this.ModuleId, fileID);
                if (!config.EnableVersioning)
                {
                    fileSystem.DeleteFile(VirtualPathUtility.Combine(fileVirtualBasePath, sharedFile.ServerFileName));
                }
                sharedFile.Delete();

                sharedFile.ContentChanged += new ContentChangedEventHandler(sharedFile_ContentChanged);

            }
        }
示例#2
0
        private void btnDeleteFile_Click(object sender, EventArgs e)
        {
            SharedFile sharedFile = new SharedFile(moduleId, itemId);
            if (sharedFile.ModuleId != moduleId)
            {
                SiteUtils.RedirectToAccessDeniedPage(this);
                return;
            }

            sharedFile.ContentChanged += new ContentChangedEventHandler(sharedFile_ContentChanged);

            if (config.EnableVersioning)
            {
                SharedFilesHelper.CreateHistory(sharedFile, fileSystem, virtualSourcePath, virtualHistoryPath);
            }

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

            WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
        }
        public static void DeleteAllFiles(SharedFileFolder folder, IFileSystem fileSystem, string fileVirtualBasePath, SharedFilesConfiguration config)
        {
            // method implemented by Jean-Michel 2008-07-31

            // TODO: implement check whether versioning is enabled before calling this method
            // if we are keeping versions we should not delete the files

            if (folder == null) { return; }
            if (fileSystem == null) { return; }
            if (string.IsNullOrEmpty(fileVirtualBasePath)) { return; }
            if (folder.FolderId == -1) { return; }

            ArrayList folders = new ArrayList();
            ArrayList files = new ArrayList();
            using (IDataReader reader = SharedFile.GetSharedFiles(folder.ModuleId, folder.FolderId))
            {
                while (reader.Read())
                {
                    files.Add(Convert.ToInt32(reader["ItemID"]));
                }
            }

            using (IDataReader reader = SharedFileFolder.GetSharedFolders(folder.ModuleId, folder.FolderId))
            {
                while (reader.Read())
                {
                    folders.Add(Convert.ToInt32(reader["FolderID"]));
                }
            }

            foreach (int id in files)
            {
                SharedFile sharedFile = new SharedFile(folder.ModuleId, id);
                sharedFile.Delete();

                if (!config.EnableVersioning)
                {
                    fileSystem.DeleteFile(VirtualPathUtility.Combine(fileVirtualBasePath, sharedFile.ServerFileName));

                }
            }

            foreach (int id in folders)
            {
                SharedFileFolder subFolder = new SharedFileFolder(folder.ModuleId, id);

                DeleteAllFiles(subFolder, fileSystem, fileVirtualBasePath, config);

                SharedFileFolder.DeleteSharedFileFolder(id);
            }
        }