public override void DeleteContent(int moduleId, Guid moduleGuid)
        {
            if (SharedFilesConfiguration.DeleteFilesOnModuleDelete)
            {
                try
                {
                    SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings();

                    if (siteSettings != null)
                    {
                        string fileVirtualBasePath = "~/Data/Sites/" + siteSettings.SiteId.ToInvariantString() + "/SharedFiles/";

                        FileSystemProvider p = FileSystemManager.Providers[WebConfigSettings.FileSystemProvider];
                        if (p != null)
                        {
                            IFileSystem fileSystem = p.GetFileSystem();
                            if (fileSystem != null)
                            {
                                using (IDataReader reader = SharedFile.GetHistoryByModule(moduleId))
                                {
                                    while (reader.Read())
                                    {
                                        string fileName = reader["ServerFileName"].ToString();
                                        fileSystem.DeleteFile(VirtualPathUtility.Combine(fileVirtualBasePath + "History/", fileName));
                                    }
                                }

                                using (IDataReader reader = SharedFile.GetSharedFiles(moduleId))
                                {
                                    while (reader.Read())
                                    {
                                        string fileName = reader["ServerFileName"].ToString();
                                        fileSystem.DeleteFile(VirtualPathUtility.Combine(fileVirtualBasePath, fileName));
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex);
                }
            }

            SharedFile.DeleteByModule(moduleId);
        }
Example #2
0
        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);
            }
        }