public static string UploadFilter(enUploadType type) { string filter = ""; if (type == enUploadType.Images) { filter = "All supported graphics|*.jpg;*.jpeg;*.png|" + "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" + "Portable Network Graphic (*.png)|*.png"; } else if (type == enUploadType.Files) { filter = "AllFiles|*.*"; } return(filter); }
public static string UploadFile(enUploadType type, Stream file, string filename) { try { string path = "./files"; if (type == enUploadType.Images) { path = path + "/images"; } else if (type == enUploadType.Files) { path = path + "/files"; } if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = path + "/" + filename; if (File.Exists(path)) { File.Delete(path); } BinaryReader reader = new BinaryReader(file); FileStream fstream = new FileStream(path, FileMode.CreateNew); BinaryWriter wr = new BinaryWriter(fstream); wr.Write(reader.ReadBytes((int)file.Length)); wr.Close(); fstream.Close(); return(path); } catch (Exception ex) { } return(""); }