public bool Delete(String sourcePath) { bool result = false; if (itemID == -1) { return(result); } if (sourcePath != null) { SharedFile sharedFile = new SharedFile(moduleID, itemID); String filePath = Path.Combine(sourcePath, Path.GetFileName(sharedFile.ServerFileName)); if (File.Exists(filePath)) { File.Delete(filePath); } } //IndexHelper.RemoveIndexItem(moduleID, itemID); DBSharedFiles.DeleteHistoryByItemID(itemID); // this just deletes the entry from the db result = DBSharedFiles.DeleteSharedFile(itemID); if (result) { ContentChangedEventArgs e = new ContentChangedEventArgs(); e.IsDeleted = true; OnContentChanged(e); } return(result); }
public static DataTable GetFoldersAndFiles(int moduleId, int parentId) { DataTable dt = new DataTable(); dt.Columns.Add("ID", typeof(string)); dt.Columns.Add("filename", typeof(string)); dt.Columns.Add("OriginalFileName", typeof(string)); dt.Columns.Add("Description", typeof(string)); dt.Columns.Add("size", typeof(int)); dt.Columns.Add("type", typeof(int)); dt.Columns.Add("DownloadCount", typeof(string)); dt.Columns.Add("modified", typeof(DateTime)); dt.Columns.Add("username", typeof(string)); DataRow dr; using (IDataReader reader = GetSharedFolders(moduleId, parentId)) { while (reader.Read()) { dr = dt.NewRow(); dr["ID"] = reader["FolderID"].ToString() + "~folder"; dr["filename"] = reader["FolderName"]; dr["OriginalFileName"] = string.Empty; dr["Description"] = string.Empty; dr["size"] = reader["SizeInKB"].ToString(); dr["type"] = "0"; dr["DownloadCount"] = string.Empty; dt.Rows.Add(dr); } } using (IDataReader reader = SharedFile.GetSharedFiles(moduleId, parentId)) { while (reader.Read()) { dr = dt.NewRow(); dr["ID"] = reader["ItemID"].ToString() + "~file"; dr["filename"] = reader["FriendlyName"]; dr["OriginalFileName"] = reader["OriginalFileName"]; dr["Description"] = reader["Description"]; dr["size"] = reader["SizeInKB"].ToString(); dr["type"] = "1"; dr["modified"] = Convert.ToDateTime(reader["UploadDate"]); dr["username"] = reader["UserName"].ToString(); dr["DownloadCount"] = reader["DownloadCount"].ToString(); dt.Rows.Add(dr); } } dt.AcceptChanges(); return(dt); }
public static bool RestoreHistoryFile(int historyId, string sourcePath, string historyPath) { bool historyRestored = false; if ((sourcePath != null) && (historyPath != null)) { 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 = DBSharedFiles.GetHistoryFile(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); sharedFile.CreateHistory(sourcePath, historyPath); File.Move(Path.Combine(historyPath, Path.GetFileName(historyServerName)), Path.Combine(sourcePath, Path.GetFileName(historyServerName))); sharedFile.ServerFileName = historyServerName; sharedFile.OriginalFileName = historyOriginalName; sharedFile.FriendlyName = historyFriendlyName; sharedFile.SizeInKB = historyFileSize; sharedFile.UploadDate = historyUploadDate; sharedFile.UploadUserId = historyUploadUserID; historyRestored = sharedFile.Update(); SharedFile.DeleteHistory(historyId, historyPath); } return(historyRestored); }
public void DeleteAllFiles(string fileBasePath) { // 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 (FolderId == -1) { return; } ArrayList folders = new ArrayList(); ArrayList files = new ArrayList(); using (IDataReader reader = SharedFile.GetSharedFiles(ModuleId, FolderId)) { while (reader.Read()) { files.Add(Convert.ToInt32(reader["ItemID"])); } } using (IDataReader reader = SharedFileFolder.GetSharedFolders(ModuleId, FolderId)) { while (reader.Read()) { folders.Add(Convert.ToInt32(reader["FolderID"])); } } foreach (int id in files) { SharedFile sharedFile = new SharedFile(ModuleId, id); sharedFile.Delete(fileBasePath); } foreach (int id in folders) { SharedFileFolder folder = new SharedFileFolder(ModuleId, id); folder.DeleteAllFiles(fileBasePath); SharedFileFolder.DeleteSharedFileFolder(id); } }