FileManager Table of contents FileManager Table of contents General info Technologies Setup Model Returned Status FileMessage Methods Get Get name Get size Create Delete Exceptions Code Examples Get GetList GetName GetNames GetSize Create Delete General info FileManager is the library to management files in your project. Technologies C# EntityFramework - version 6.2.0 Setup Add following config to your web.config: <configuration> <configSections> <section name="FileManager" type="FileManagerLibrary.Config.Section"/> </configSections> <FileManager> <DbConfig connectionString="CONNECTION STRING TO DATABASE"/> <DirectoryConfig path="~/BASE DIRECTORY"/> <!-- Optional parameter --> <CustomConfig maxFileSize="MAX FILE SIZE IN KB"/> </FileManager> </configuration> Model public class StorageFile { public long Id { get; set; } [Required] public Guid PublicId { get; set; } [Required] public DateTime DateCreatedUtc { get; set; } [Required] public string CreatedBy { get; set; } [Required] public string Name { get; set; } [Required] public string ContentType { get; set; } [Required] public int ContentLength { get; set; } [Required] public string Directory { get; set; } [NotMapped] public FileStream FileStream { get; set; } } Returned Status public enum Status { NotExists = 0, Exists = 1, SizeIsToBig = 2, Ok = 9 } FileMessage public class FileMessage { public HttpPostedFileBase File { get; set; } public StorageFile.Status Status { get; set; } } Methods Get Returned type Method name Parameters Description StorageFile Get long id, bool withDependencies = false withDependencies: true: return record from database with file from disk false: return only record from database StorageFile Get Guid publicId, bool withDependencies = false withDependencies: true: return record from database with file from disk false: return only record from database List<StorageFile> GetList List<long> ids, bool withDependencies = false withDependencies: true: return records from database with files from disk false: return only records from database List<StorageFile> GetList List<Guid> publicIds, bool withDependencies = false withDependencies: true: return records from database with files from disk false: return only records from database Get name Returned type Method name Parameters Description string GetName long id string GetName Guid publicId List<string> GetNames List<long> ids List<string> GetNames List<Guid> publicIds Get size Returned type Method name Parameters Description int? GetSize long id Create Returned type Method name Parameters Description StorageFile.Status Create HttpPostedFileBase file, string directory, string createdBy List<FileMessage> Create HttpPostedFileBase[] files, string directory, string createdBy Delete Returned type Method name Parameters Description StorageFile.Status Delete Guid publicId StorageFile.Status Delete long id StorageFile.Status Delete StorageFile record StorageFile.Status Delete List<long> ids StorageFile.Status Delete List<Guid> publicIds StorageFile.Status Delete List<StorageFile> files Exceptions Name Description FileManagerException If any exception occurs in methods Code Examples Show examples of usage: Get try { var file = FilesRepository.Get(2, withDependencies: true); } catch (FileManagerException ex) { throw; } GetList var testList = new List<long>(){1, 2, 3}; try { var files = FilesRepository.GetList(testList, withDependencies: true); } catch (FileManagerException ex) { throw; } GetName try { var fileName = FilesRepository.GetName(3); } catch (FileManagerException ex) { throw; } GetNames var testList = new List<long>(){1, 2, 3}; try { var fileNames = FilesRepository.GetNames(testList); } catch (FileManagerException ex) { throw; } GetSize try { var fileSize = FilesRepository.GetSize(3); //possible null } catch (FileManagerException ex) { throw; } Create Delete try { //var file = FilesRepository.Get(3); //var status = FilesRepository.Delete(file); //var testList = new List<long>(){1, 2, 3}; //var files = FilesRepository.GetList(testList); //var status = FilesRepository.Delete(files); //var testList = new List<long>(){1, 2, 3}; //var status = FilesRepository.Delete(testList); var status = FilesRepository.Delete(3); if (status != StorageFile.Status.Ok) { switch (status) { case StorageFile.Status.NotExists: break; } [HttpPost] [ValidateAntiForgeryToken] public ActionResult Test(HttpPostedFileBase file) { try { var status = FilesRepository.Create(file, "directory", "createdBy"); if (status != StorageFile.Status.Ok) { switch (status) { case StorageFile.Status.Exists: break; case StorageFile.Status.SizeIsToBig: break; } } } catch (FileManagerException ex) { throw; } return View(); } } } catch (FileManagerException ex) { throw; }