public static void CopyStreamToFile(this Stream input, string fileName) { using (Stream file = File.OpenWrite(fileName)) { input.CopyStream(file); } }
/// <summary> /// Saves a stream to the specified path /// </summary> /// <param name="path">The relative or absolute path to save the file</param> /// <param name="context">The context to be used when mapping the path to its physical self</param> public static void Save(this Stream s, string path, HttpContextBase context) { path = PathTools.EnsurePhysical(path, context); using (FileStream fs = new FileStream(path, FileMode.CreateNew, FileAccess.Write)) s.CopyStream(fs); }
public static void SaveToFile(this Stream stream, string filePath) { var directory = Path.GetDirectoryName(filePath) + ""; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } using (var fileStream = File.OpenWrite(filePath)) { stream.CopyStream(fileStream); } }
/// <summary> /// Reads entire <see cref="Stream"/> contents, and returns <see cref="byte"/> array of data. /// </summary> /// <param name="source">The <see cref="Stream"/> to be converted to <see cref="byte"/> array.</param> /// <returns>An array of <see cref="byte"/>.</returns> public static byte[] ReadStream(this Stream source) { MemoryStream outStream = new MemoryStream(); source.CopyStream(outStream); return outStream.ToArray(); }