public ActionResult ShowFileData(int fileid) { try { if (!db.Files.Any(m => m.fileid == fileid)) { return(RedirectToAction("Partial_Toast", "Toast", NoSuchFile())); } string fileExt = db.Files.Include(m => m.FileExtension).FirstOrDefault(m => m.fileid == fileid)?.FileExtension?.displayname; if (ImageFileExtensions.Any(fileExt.Contains)) { var file = db.Files.Include(m => m.FileExtension).FirstOrDefault(m => m.fileid == fileid); return(PartialView("_PartialShowFileImage", new FileEditModel(file))); } if (TextFileExtensions.Any(fileExt.Contains)) { var file = db.Files.Include(m => m.FileExtension).FirstOrDefault(m => m.fileid == fileid); file.FileContentAsString = file.file_content != null?Encoding.UTF8.GetString(file.file_content) : ""; return(PartialView("_PartialShowFileData", new FileEditModel(file))); } // загрузка данных файла без контента файла File fileWithoutData = db.Files.AsEnumerable().Where(m => m.fileid == fileid).Select(m => new File { fileid = m.fileid, FileExtension = m.FileExtension, description = m.description, displayname = m.displayname, folderid = m.folderid }).FirstOrDefault(); string extName = fileWithoutData.FileExtension?.icon_filename ?? fileWithoutData.FileExtension.displayname + ".svg"; string relativePath = "/Content/FileIcons/" + extName; string fullpath = HttpContext.Server.MapPath(relativePath); if (System.IO.File.Exists(fullpath)) { fileWithoutData.IconFileName = extName; } else { fileWithoutData.IconFileName = "unknown.svg"; } return(PartialView("_PartialShowFileExtension", new FileEditModel(fileWithoutData))); } catch (Exception ex) { return(RedirectToAction("Partial_UnknownErrorToast", "Toast")); } }
private MediaItem GetMediaItem(string file) { if (MovieFileExtensions.Any(ex => file.ToLower().EndsWith(ex, StringComparison.Ordinal)) && _mediaTypes.HasFlag(MediaType.Video)) { return new MediaItem { MediaType = MediaType.Video, Path = "file://" + file } } ; if (ImageFileExtensions.Any(ex => file.ToLower().EndsWith(ex, StringComparison.Ordinal)) && _mediaTypes.HasFlag(MediaType.Image)) { return new MediaItem { MediaType = MediaType.Image, Path = file } } ; return(null); }