Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private Attachment CreateBinaryFile(string fileName)
- {
- if (string.IsNullOrEmpty(fileName))
- return null;
- if (!File.Exists(fileName))
- {
- throw new FileNotFoundException("Файл не найден или нет доступа", fileName);
- }
- var mimeMappingService = Locator.GetServiceNotNull<IMimeMappingService>();
- var binaryFile = new BinaryFile {
- ContentType = mimeMappingService.GetTypeByExtension(Path.GetExtension(fileName)),
- Name = Path.GetFileName(fileName),
- ContentFilePath = fileName,
- CreateDate = DateTime.Now,
- };
- binaryFile.InitializeContentFilePath();
- File.Copy(fileName, binaryFile.ContentFilePath);
- var fileManager = Locator.GetServiceNotNull<IFileManager>();
- fileManager.SaveFile(binaryFile);
- return new Attachment() {
- File = binaryFile
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement