zhao
2021-07-19 8347f2fbddbd25369359dcb2da1233ac48a19fdc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
 
namespace HH.WMS.Utils
{
    public partial class ZFiles
    {
        public static void SaveStreamToFile(Stream FromStream, string TargetFile)
        {
            // FromStream=the stream we wanna save to a file 
            //TargetFile = name&path of file to be created to save to 
            //i.e"c:\mysong.mp3" 
            try
            {
                //Creat a file to save to
                Stream ToStream = File.Create(TargetFile);
 
                //use the binary reader & writer because
                //they can work with all formats
                //i.e images, text files ,avi,mp3..
                BinaryReader br = new BinaryReader(FromStream);
                BinaryWriter bw = new BinaryWriter(ToStream);
 
                //copy data from the FromStream to the outStream
                //convert from long to int 
                bw.Write(br.ReadBytes((int)FromStream.Length));
                //save
                bw.Flush();
                //clean up 
                bw.Close();
                br.Close();
            }
 
             //use Exception e as it can handle any exception 
            catch (Exception e)
            {
                //code if u like 
            }
        }
    }
}