Exemplo n.º 1
0
        public string SaveImageFile(IFormFileCollection filelist)
        {
            try
            {
                IFormFile file      = filelist[0];                                            //默认值上传一张图片;获取第一个文件
                string    filename  = FileManage.GenerateFileName(file.FileName);             //上传文件名(唯一)
                string    recv_Path = Path.Combine(FileManage.GetSaveFolderPath(), filename); //保存路径+文件名

                try
                {
                    using (FileStream fs = new FileStream(recv_Path, FileMode.Create, FileAccess.Write))
                    {
                        file.CopyTo(fs);
                    }

                    return(recv_Path);
                }
                catch (Exception)
                {
                    throw new MyException("上传文件写入异常! 写入路径:" + recv_Path);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
        public static string[] SaveFile(IFormFileCollection filelist)
        {
            string[] filenames = new string[filelist.Count];
            for (int i = 0; i < filelist.Count; i++)
            {
                try
                {
                    IFormFile file = filelist[i];
                    //string filename = FileManage.GenerateFileName(file.FileName); //上传文件名(唯一)
                    string filename  = file.FileName;                                          //上传文件名(唯一)
                    string recv_Path = Path.Combine(FileManage.GetSaveFolderPath(), filename); //保存路径+文件名

                    using (FileStream fs = new FileStream(recv_Path, FileMode.Create, FileAccess.Write))
                    {
                        file.CopyTo(fs);
                    }
                    filenames[i] = recv_Path;
                }
                catch (Exception)
                {
                    filenames[i] = string.Empty;
                    throw new MyException("上传文件写入异常! ");
                }
            }
            return(filenames);
        }