MemoryStream stream
BinaryWriter bw = new BinaryWriter(stream); for (Int32 i = 0; i < 100; i++) { bw.Write(100); } FileStream dumpFile = new FileStream(System.Web.HttpContext.Current.Request.MapPath("~/a.txt"), FileMode.Create, FileAccess.ReadWrite); stream.WriteTo(dumpFile); dumpFile.Flush(); dumpFile.Close();