Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How can i save a file stream to a folder as file?

how to save below fs as file?

C#
FileStream fs = new FileStream(upload.FilePath, FileMode.Open, FileAccess.Read);
         byte[] ImageData = new byte[fs.Length];
         fs.Read(ImageData, 0, System.Convert.ToInt32(fs.Length));
         fs.Close();
Posted

Why do you post the same question twice? Please delete the earlier one: How Can I Save A File Stream To A Folder As File?[^]
You can use this method:
C#
public void CopyStream(Stream stream, string destPath)
{
  using (var fileStream = new FileStream(destPath, FileMode.Create, FileAccess.Write))
  {
    stream.CopyTo(fileStream);
  }
}


For more solutions see:
How do I save a stream to a file in C#?[^]
 
Share this answer
 
Comments
Am Gayathri 9-Dec-15 7:22am    
How can i read file from file stream and create save file in folder?
Tried above code, File created but size is 0KB always.
ridoy 9-Dec-15 9:25am    
That means your stream data in null.
ridoy 9-Dec-15 9:27am    
You can read file by following this code example: http://www.csharp-examples.net/filestream-read-file/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900