public static string[] GetFiles(string path = "") { string[] result = null; try { var files = Directory.GetFiles(String.Format("{0}/{1}", MediaPath, path)); result = files.Select(f => new FileInfo(f)).Where(f => AvailableExtension.Contains(f.Extension)).Select(f => f.Name).ToArray(); } catch (Exception e) { } return result; }
public static bool SaveFile(string folder, string fileName, byte[] data) { var result = false; try { if (!String.IsNullOrEmpty(folder) && !String.IsNullOrEmpty(fileName)) { var file = new FileInfo(String.Format("{0}/{1}/{2}", MediaPath, folder, fileName)); if (AvailableExtension.Contains(file.Extension)) { File.WriteAllBytes(file.FullName, data); result = true; } } } catch (Exception e) { } return result; }
public static bool RemoveFile(string folder, string fileName) { var result = false; try { if (!String.IsNullOrEmpty(folder) && !String.IsNullOrEmpty(fileName)) { var path = String.Format("{0}/{1}/{2}", MediaPath, folder, fileName); if (File.Exists(path)) { var file = new FileInfo(path); if (AvailableExtension.Contains(file.Extension)) { File.Delete(path); result = true; } } } } catch (Exception e) { } return result; }
public static bool SaveFile(string folder, string fileName, Stream stream, out FileInfo file) { var result = false; file = null; try { if (!String.IsNullOrEmpty(folder) && !String.IsNullOrEmpty(fileName)) { file = new FileInfo(String.Format("{0}/{1}/{2}", MediaPath, folder, fileName)); Functions.CheckDirectory(file.DirectoryName); if (AvailableExtension.Contains(file.Extension)) { using (var fileStream = System.IO.File.Create(file.FullName)) { stream.CopyTo(fileStream); } result = true; } } } catch (Exception e) { } return result; }