jt
2021-06-10 5d0d028456874576560552f5a5c4e8b801786f11
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/********************************************************************************
 
** auth: DBS
 
** date: 2019/3/6 9:50:09
 
** desc: 尚未编写描述
 
** Ver.:  V1.0.0
 
*********************************************************************************/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace HH.WMS.Common{
    public static class FileUtils
    {
        #region 保存文件
        /// <summary>
        /// 保存文件
        /// </summary>
        /// <param name="file">文件字节</param>
        /// <param name="path">保存路径</param>
        /// <param name="fileName">文件名</param>
        /// <returns></returns>
        public static string SaveFile(byte[] file, string path, string fileName)
        {
            try
            {
                var filename = fileName;
                var filePath = string.Format(@"{0}\{1}", path, filename);     //保存完整路径
                var fullpath = filePath;     //流写入路径
                //创建文件   
                using (var ms = new MemoryStream())
                {
                    MemoryStream m = new MemoryStream(file);
                    string files = string.Format(@"{0}", fullpath);
                    FileStream fs = new FileStream(files, FileMode.OpenOrCreate);
                    m.WriteTo(fs);
                    m.Close();
                    fs.Close();
                    m = null;
                    fs = null;
                    return fullpath;
                }
            }
            catch (Exception)
            {
                return "";
            }
        }
        #endregion
    }
}