public List <FileViewModel> GetFiles(string fullPath) { CreateDirectoryIfNotExist(fullPath); FileInfo[] Files; List <FileViewModel> result = new List <FileViewModel>(); foreach (string dirPath in Directory.GetDirectories(fullPath, "*", SearchOption.AllDirectories)) { DirectoryInfo path = new DirectoryInfo(dirPath); string folderName = path.Name; Files = path.GetFiles(); foreach (var file in Files.OrderByDescending(f => f.CreationTimeUtc)) { result.Add(new FileViewModel() { FolderName = folderName, FileFolder = MixCommonHelper.GetFullPath(new string[] { fullPath, folderName }), Filename = file.Name.Substring(0, file.Name.LastIndexOf('.')), Extension = file.Extension, //Content = s.ReadToEnd() }); } } return(result); }
public List <FileViewModel> GetWebFiles(string folder) { string fullPath = MixCommonHelper.GetFullPath(new string[] { "wwwroot", folder }); CreateDirectoryIfNotExist(fullPath); FileInfo[] Files; List <FileViewModel> result = new List <FileViewModel>(); foreach (string dirPath in Directory.GetDirectories(fullPath, "*", SearchOption.AllDirectories)) { DirectoryInfo path = new DirectoryInfo(dirPath); string folderName = path.ToString().Replace(@"\", "/").Replace("wwwroot", string.Empty); Files = path.GetFiles(); foreach (var file in Files.OrderByDescending(f => f.CreationTimeUtc)) { result.Add(new FileViewModel() { FolderName = path.Name, FileFolder = folderName, Filename = file.Name.LastIndexOf('.') >= 0 ? file.Name.Substring(0, file.Name.LastIndexOf('.')) : file.Name, Extension = file.Extension }); } } return(result); }
public List <FileViewModel> GetUploadFiles(string folder) { string fullPath = MixCommonHelper.GetFullPath(new string[] { folder }); CreateDirectoryIfNotExist(fullPath); DirectoryInfo d = new DirectoryInfo(fullPath); //Assuming Test is your Folder FileInfo[] Files = d.GetFiles(); List <FileViewModel> result = new List <FileViewModel>(); foreach (var file in Files.OrderByDescending(f => f.CreationTimeUtc)) { using (StreamReader s = file.OpenText()) { result.Add(new FileViewModel() { FileFolder = folder, Filename = file.Name.Substring(0, file.Name.LastIndexOf('.')), Extension = file.Extension, Content = s.ReadToEnd() }); } } return(result); }
public FileViewModel GetUploadFile(string name, string ext, string fileFolder) { FileViewModel result = null; string folder = MixCommonHelper.GetFullPath(new string[] { fileFolder }); string fullPath = string.Format(@"{0}/{1}.{2}", folder, name, ext); FileInfo file = new FileInfo(fullPath); try { using (StreamReader s = file.OpenText()) { result = new FileViewModel() { FileFolder = fileFolder, Filename = file.Name.Substring(0, file.Name.LastIndexOf('.')), Extension = file.Extension.Remove(0, 1), Content = s.ReadToEnd() }; } } catch { // File invalid } return(result ?? new FileViewModel() { FileFolder = fileFolder }); }
public bool SaveWebFile(FileViewModel file) { try { string fullPath = $"wwwroot/{file.FileFolder}"; if (!string.IsNullOrEmpty(file.Filename)) { CreateDirectoryIfNotExist(fullPath); string fileName = MixCommonHelper.GetFullPath(new string[] { fullPath, file.Filename + file.Extension }); if (File.Exists(fileName)) { DeleteFile(fileName); } if (!string.IsNullOrEmpty(file.Content)) { using (var writer = File.CreateText(fileName)) { writer.WriteLine(file.Content); //or .Write(), if you wish return(true); } } else { if (IsImage(file.Extension)) { // XL ResizeImage(file, "XL"); // L ResizeImage(file, "L"); // M ResizeImage(file, "M"); // S ResizeImage(file, "S"); // XS ResizeImage(file, "XS"); // XXS ResizeImage(file, "XXS"); ResizeImage(file); return(true); } else { return(SaveFile(file)); } } } else { return(false); } } catch { return(false); } }
public bool DeleteFile(string name, string extension, string FileFolder) { string folder = MixCommonHelper.GetFullPath(new string[] { FileFolder }); string fullPath = string.Format(@"{0}/{1}{2}", folder, name, extension); if (File.Exists(fullPath)) { MixCommonHelper.RemoveFile(fullPath); } return(true); }
public bool DeleteWebFolder(string folderPath) { string fullPath = MixCommonHelper.GetFullPath(new string[] { "wwwroot", folderPath }); if (Directory.Exists(fullPath)) { Directory.Delete(fullPath, true); } return(true); }
public bool DeleteWebFile(string filePath) { string fullPath = MixCommonHelper.GetFullPath(new string[] { "wwwroot", filePath }); if (File.Exists(fullPath)) { MixCommonHelper.RemoveFile(fullPath); } return(true); }