Beispiel #1
0
        /// <summary>
        /// 上传单个文件, 客户端需要多次调用
        /// 客户端控制文件保存路径
        /// </summary>
        /// <param name="filedata">文件信息及stream</param>
        /// <returns></returns>
        public UpFileResult UpLoadFile(UpFile filedata)
        {
            UpFileResult result = new UpFileResult();

            // etc ..\blades\partId
            string path = Path.Combine(PathManager.Instance.RootPath, filedata.FilePath);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            byte[]     buffer       = new byte[filedata.FileSize];
            string     fileFullPath = Path.Combine(path, filedata.FileName);
            FileStream fs           = new FileStream(fileFullPath, FileMode.Create, FileAccess.Write);

            int count = 0;

            while ((count = filedata.FileStream.Read(buffer, 0, buffer.Length)) > 0)
            {
                fs.Write(buffer, 0, count);
            }
            //清空缓冲区
            fs.Flush();
            //关闭流
            fs.Close();

            result.IsSuccess = true;

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// 上传文件,到文件缓存目录
        /// </summary>
        /// <param name="filedata"></param>
        /// <returns></returns>
        private static UpFileResult UpLoadfilebuffer(UpFile filedata)
        {
            if (!Directory.Exists(filebufferpath))
            {
                Directory.CreateDirectory(filebufferpath);
            }
            string     _filename = DateTime.Now.Ticks.ToString() + filedata.FileExt;//生成唯一文件名,防止文件名相同会覆盖
            FileStream fs        = new FileStream(filebufferpath + _filename, FileMode.Create, FileAccess.Write);

            using (fs)
            {
                int    bufferlen = 4096;
                int    count     = 0;
                byte[] buffer    = new byte[bufferlen];
                while ((count = filedata.FileStream.Read(buffer, 0, bufferlen)) > 0)
                {
                    fs.Write(buffer, 0, count);
                }

                //清空缓冲区
                //fs.Flush();
                //关闭流
                //fs.Close();
            }


            UpFileResult result = new UpFileResult();

            result.IsSuccess = true;
            result.Message   = _filename;//返回保存文件

            return(result);
        }
        /// <summary>
        /// 上传文件,上传文件的进度只能通过时时获取服务端Read的进度
        /// </summary>
        /// <param name="filepath">文件本地路径</param>
        /// <returns>上传成功后返回的文件名</returns>
        public static string UpLoadFile(string filepath, Action <int> action)
        {
            ChannelFactory <IFileTransfer> mfileChannelFactory = null;
            IFileTransfer fileHandlerService = null;

            try
            {
                FileInfo finfo = new FileInfo(filepath);
                if (finfo.Exists == false)
                {
                    throw new Exception("文件不存在!");
                }

                mfileChannelFactory = new ChannelFactory <IFileTransfer>("fileendpoint");
                fileHandlerService  = mfileChannelFactory.CreateChannel();

                UpFile uf = new UpFile();
                if (AppGlobal.cache.Contains("WCFClientID"))
                {
                    uf.clientId = AppGlobal.cache.GetData("WCFClientID").ToString();
                }
                uf.UpKey      = Guid.NewGuid().ToString();
                uf.FileExt    = finfo.Extension;
                uf.FileName   = finfo.Name;
                uf.FileSize   = finfo.Length;
                uf.FileStream = finfo.OpenRead();

                if (action != null)
                {
                    getUpLoadFileProgress(uf.UpKey, action);//获取上传进度条
                }
                UpFileResult result = fileHandlerService.UpLoadFile(uf);

                //mfileChannelFactory.Close();//关闭会话

                if (result.IsSuccess)
                {
                    return(result.Message);
                }
                else
                {
                    throw new Exception("上传文件失败!");
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message + "\n上传文件失败!");
            }
            finally
            {
                if (fileHandlerService != null)
                {
                    (fileHandlerService as IContextChannel).Close();
                }
                if (mfileChannelFactory != null)
                {
                    mfileChannelFactory.Close();
                }
            }
        }
Beispiel #4
0
        public UpFileResult UpLoadFile(UpFile filedata)
        {
            UpFileResult result = new UpFileResult();

            string path = System.AppDomain.CurrentDomain.BaseDirectory + @"\service\";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            byte[] buffer = new byte[filedata.FileSize];

            FileStream fs = new FileStream(path + filedata.FileName, FileMode.Create, FileAccess.Write);

            int count = 0;

            while ((count = filedata.FileStream.Read(buffer, 0, buffer.Length)) > 0)
            {
                fs.Write(buffer, 0, count);
            }
            //清空缓冲区
            fs.Flush();
            //关闭流
            fs.Close();

            result.IsSuccess = true;

            return(result);
        }
Beispiel #5
0
        /// <summary>
        /// 上传文件,保存到Mongodb
        /// </summary>
        /// <param name="filedata"></param>
        /// <returns></returns>
        private static UpFileResult UpLoadMongodb(UpFile filedata)
        {
            UpFileResult result = new UpFileResult();

            result.IsSuccess = true;
            result.Message   = "数据上传到Mongodb成功!";

            return(result);
        }
Beispiel #6
0
        /// <summary>
        /// 上传文件,程序升级包
        /// </summary>
        /// <param name="filedata"></param>
        /// <returns></returns>
        private static UpFileResult UpLoadUpgrade(UpFile filedata)
        {
            UpFileResult result = new UpFileResult();

            result.IsSuccess = true;
            result.Message   = "升级包上传成功!";

            return(result);
        }
Beispiel #7
0
        public UpFileResult UpLoadFile1(UpFile1 filedata)
        {
            UpFileResult result = new UpFileResult();

            //// etc ..\blades\partId
            //string path = Path.Combine(PathManager.Instance.Configration.RootPath, filedata.FilePath);
            string path;

            if (filedata.selPath == 0) // 程序类文件
            {
                path = PathManager.Instance.GetProgsFullPath();
            }
            else if (filedata.selPath == 1) // Blades类文件
            {
                path = PathManager.Instance.GetBladesFullPath(filedata.PartId);
            }
            else
            {
                result.IsSuccess = false;
                result.Message   = "文件目录不确定";
                return(result);
            }

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            byte[] buffer       = new byte[filedata.FileSize];
            string fileFullPath = Path.Combine(path, filedata.FileName);
            string fileext      = Path.GetExtension(filedata.FileName);

            if (File.Exists(fileFullPath) && (string.Compare(fileext, ".PRG^", true) == 0 || string.Compare(fileext, ".PRG~", true) == 0))
            {
                File.Delete(fileFullPath); // 删除PCDmis自动生成的隐藏文件
            }
            FileStream fs = new FileStream(fileFullPath, FileMode.Create, FileAccess.Write);

            int count = 0;

            while ((count = filedata.FileStream.Read(buffer, 0, buffer.Length)) > 0)
            {
                fs.Write(buffer, 0, count);
            }
            //清空缓冲区
            fs.Flush();
            //关闭流
            fs.Close();

            result.IsSuccess = true;

            return(result);
        }
Beispiel #8
0
        /// <summary>
        /// 上传文件,有进度显示
        /// </summary>
        /// <param name="filepath">文件本地路径</param>
        /// <param name="action">进度0-100</param>
        /// <returns>上传成功后返回的文件名</returns>
        public string UpLoadFile(string filepath, Action <int> action)
        {
            IFileTransfer fileHandlerService = null;

            try
            {
                FileInfo finfo = new FileInfo(filepath);
                if (finfo.Exists == false)
                {
                    throw new Exception("文件不存在!");
                }


                fileHandlerService = mfileChannelFactory.CreateChannel();

                UpFile uf = new UpFile();
                uf.clientId   = mConn == null ? "" : mConn.ClientID;
                uf.UpKey      = Guid.NewGuid().ToString();
                uf.FileExt    = finfo.Extension;
                uf.FileName   = finfo.Name;
                uf.FileSize   = finfo.Length;
                uf.FileStream = finfo.OpenRead();

                if (action != null)
                {
                    getupdownprogress(uf.FileStream, uf.FileSize, action);//获取进度条
                }
                UpFileResult result = new UpFileResult();
                result = fileHandlerService.UpLoadFile(uf);

                if (result.IsSuccess)
                {
                    return(result.Message);
                }
                else
                {
                    throw new Exception("上传文件失败!");
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message + "\n上传文件失败!");
            }
            finally
            {
                if (fileHandlerService != null)
                {
                    (fileHandlerService as IContextChannel).Abort();
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="filedata"></param>
        /// <returns></returns>
        public static UpFileResult UpLoadFile(UpFile filedata)
        {
            try
            {
                if (WcfGlobal.IsDebug)
                {
                    ShowHostMsg(Color.Black, DateTime.Now, "客户端[" + filedata.clientId + "]准备上传文件...");
                    //获取进度
                    getupdownprogress(filedata.FileStream, filedata.FileSize, (delegate(int _num)
                    {
                        ShowHostMsg(Color.Black, DateTime.Now, "客户端[" + filedata.clientId + "]上传文件进度:%" + _num);
                    }));
                }

                UpFileResult result = new UpFileResult();

                if (filedata.FileType == 0)//0:filebuffer目录  1:Upgrade升级包 2:Mongodb
                {
                    result = UpLoadfilebuffer(filedata);
                }
                else if (filedata.FileType == 1)
                {
                    result = UpLoadUpgrade(filedata);
                }
                else if (filedata.FileType == 2)
                {
                    result = UpLoadMongodb(filedata);
                }
                else
                {
                    result = UpLoadfilebuffer(filedata);
                }

                if (WcfGlobal.IsDebug)
                {
                    ShowHostMsg(Color.Green, DateTime.Now, "客户端[" + filedata.clientId + "]上传文件完成");
                }

                return(result);
            }
            catch (Exception err)
            {
                //记录错误日志
                EFWCoreLib.CoreFrame.EntLib.ZhyContainer.CreateException().HandleException(err, "HISPolicy");
                UpFileResult result = new UpFileResult();
                result.IsSuccess = false;
                return(result);
            }
        }
Beispiel #10
0
 /// <summary>
 /// 上传单个文件到服务器
 /// </summary>
 /// <param name="partId">工件标识</param>
 /// <param name="filefullPath">文件全路径名</param>
 /// <param name="selPath">相对路径,baldes\partId或者programs</param>
 /// <returns></returns>
 private bool UpFileToServer1(string partId, string filefullPath, int selPath)
 {
     using (Stream fs = new FileStream(filefullPath, FileMode.Open, FileAccess.Read))
     {
         UpFile1 fileData = new UpFile1();
         fileData.FileName   = Path.GetFileName(filefullPath);
         fileData.FileSize   = fs.Length;
         fileData.selPath    = selPath;
         fileData.FileStream = fs;
         fileData.PartId     = partId;
         UpFileResult ures = _partConfigService.UpLoadFile1(fileData);
         //if (ures.IsSuccess)
         //{
         //    Debug.WriteLine("File up ok");
         //}
         return(ures.IsSuccess);
     }
 }
Beispiel #11
0
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="uf">上传文件对象</param>
        /// <param name="action">进度条委托</param>
        /// <returns>返回上传的结果</returns>
        public string UpLoadFile(UpFile uf, Action <int> action)
        {
            if (uf == null)
            {
                throw new Exception("上传文件对象不能为空!");
            }

            try
            {
                if (action != null)
                {
                    getupdownprogress(uf.FileStream, uf.FileSize, action);//获取进度条
                }
                UpFileResult result = new UpFileResult();
                result = fileServiceClient.UpLoadFile(uf);

                if (result.IsSuccess)
                {
                    return(result.Message);
                }
                else
                {
                    throw new Exception("上传文件失败!");
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message + "\n上传文件失败!");
            }
            finally
            {
                //if (fileServiceClient != null)
                //{
                //    fileServiceClient.Close();
                //}
            }
        }
        public UpFileResult UpLoadFile(UpFile filedata)
        {
            FileStream fs = null;

            try
            {
                if (WcfServerManage.IsDebug)
                {
                    ShowHostMsg(Color.Black, DateTime.Now, "客户端[" + filedata.clientId + "]准备上传文件...");
                }

                UpFileResult result = new UpFileResult();
                if (!Directory.Exists(filebufferpath))
                {
                    Directory.CreateDirectory(filebufferpath);
                }

                string _filename = Guid.NewGuid().ToString() + filedata.FileExt;//生成唯一文件名,防止文件名相同会覆盖
                fs = new FileStream(filebufferpath + _filename, FileMode.Create, FileAccess.Write);

                int     oldprogressnum = 0;
                decimal progressnum    = 0;
                long    bufferlen      = 4096;
                int     count          = 0;
                byte[]  buffer         = new byte[bufferlen];
                while ((count = filedata.FileStream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    fs.Write(buffer, 0, count);
                    //获取上传进度
                    getprogress(filedata.FileSize, bufferlen, ref progressnum);
                    if (oldprogressnum < Convert.ToInt32(Math.Ceiling(progressnum)))
                    {
                        oldprogressnum = Convert.ToInt32(Math.Ceiling(progressnum));
                        if (progressDic_Up.ContainsKey(filedata.UpKey))
                        {
                            progressDic_Up[filedata.UpKey] = Convert.ToInt32(Math.Ceiling(progressnum));
                        }
                        else
                        {
                            progressDic_Up.Add(filedata.UpKey, Convert.ToInt32(Math.Ceiling(progressnum)));
                        }
                        if (WcfServerManage.IsDebug)
                        {
                            ShowHostMsg(Color.Black, DateTime.Now, "客户端[" + filedata.clientId + "]上传文件进度:%" + oldprogressnum);
                        }
                    }
                }

                //清空缓冲区
                fs.Flush();
                //关闭流
                fs.Close();

                if (WcfServerManage.IsDebug)
                {
                    ShowHostMsg(Color.Green, DateTime.Now, "客户端[" + filedata.clientId + "]上传文件完成");
                }

                result.IsSuccess = true;
                result.Message   = _filename;//返回保存文件

                return(result);
            }
            catch (Exception err)
            {
                if (fs != null)
                {
                    fs.Flush();
                    fs.Close();
                }
                //记录错误日志
                EFWCoreLib.CoreFrame.EntLib.ZhyContainer.CreateException().HandleException(err, "HISPolicy");
                UpFileResult result = new UpFileResult();
                result.IsSuccess = false;
                return(result);
            }
        }
        public BaseResponse <UpFileResult> UploadFile(string filename, Stream FileStream)
        {
            UpFileResult result = new UpFileResult();
            BaseResponse <UpFileResult> response = new BaseResponse <UpFileResult>();

            //#region 新上传
            //try
            //{
            //    #region 获取文件名
            //    var fName = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.RequestUri.ToString();
            //    int len = fName.Length;
            //    int pos = fName.LastIndexOf('/');
            //    var realName = fName.Substring(pos + 1, (len - pos - 1));
            //    var extention = Path.GetExtension(realName).TrimStart('.');
            //    var oldName = realName.Substring(0, realName.LastIndexOf('.'));
            //    var saveFileName = oldName + DateTime.Now.Ticks + "." + extention;

            //    #endregion


            //    using (StreamReader sr = new StreamReader(FileStream))
            //    {
            //        string pathNew = System.AppDomain.CurrentDomain.BaseDirectory + @"\UploadFiles\";

            //        if (!Directory.Exists(pathNew))
            //        {
            //            Directory.CreateDirectory(pathNew);
            //        }

            //        //var extention = Path.GetExtension(filename).TrimStart('.');
            //        //var oldName = filename.Substring(0, filename.LastIndexOf('.'));
            //        //var saveFileName = oldName + DateTime.Now.Ticks + "." + extention;


            //        string str = sr.ReadToEnd();

            //        var savePathNew = Path.Combine(pathNew, saveFileName);
            //        byte[] buffer = System.Text.Encoding.UTF8.GetBytes(str);
            //        using (FileStream fs = new FileStream(savePathNew, FileMode.OpenOrCreate))
            //        {
            //            fs.Write(buffer, 0, buffer.Length);
            //        }

            //        response.IsSuccessful = true;
            //        result.FilePath = saveFileName;
            //        response.Result = result;

            //        return response;
            //    }
            //}
            //catch (Exception e)
            //{
            //    LogHelper.WriteLog(e);
            //    response.IsSuccessful = false;
            //    response.Reason = e.Message;
            //    return response;
            //}

            //#endregion

            try
            {
                #region 获取文件名
                var fName        = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.RequestUri.ToString();
                int len          = fName.Length;
                int pos          = fName.LastIndexOf('/');
                var realName     = fName.Substring(pos + 1, (len - pos - 1));
                var extention    = Path.GetExtension(realName).TrimStart('.');
                var oldName      = realName.Substring(0, realName.LastIndexOf('.'));
                var saveFileName = oldName + DateTime.Now.Ticks + "." + extention;

                #endregion

                //获取文件大小
                long fileLength = WebOperationContext.Current.IncomingRequest.ContentLength;
                //fileLength = FileStream.Length;
                //UpFile parameter = new UpFile();

                if (true)
                {
                    string path = System.AppDomain.CurrentDomain.BaseDirectory + @"\UploadFiles\";

                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    byte[] buffer = new byte[fileLength];

                    string     filePath = Path.Combine(path, saveFileName);
                    FileStream fs       = new FileStream(filePath, FileMode.Create, FileAccess.Write);

                    int count = 0;
                    while ((count = FileStream.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        fs.Write(buffer, 0, count);
                    }
                    //清空缓冲区
                    fs.Flush();
                    //关闭流
                    fs.Close();
                    result.FilePath = saveFileName;
                    response.Result = result;
                    return(response);
                }
                else
                {
                    response.IsSuccessful = false;
                    response.Reason       = "JWT_ERR";
                    return(response);
                }
            }
            catch (Exception e)
            {
                LogHelper.WriteLog(e);
                response.IsSuccessful = false;
                response.Reason       = e.Message;
                return(response);
            }
        }
Beispiel #14
0
        public void ProcessRequest(HttpContext context)
        {
            //获取虚拟目录的物理路径。
            UpFileResult upFileResult = new UpFileResult();
            //string imgurls = "";
            //BLL.Common.Logger.Info("Count:" + context.Request.Files.Count);
            //foreach (HttpPostedFile file in context.Request.Files)
            //{
            HttpPostedFile file     = context.Request.Files[0];
            string         fileName = file.FileName;
            string         ser      = context.Request.FilePath;

            Settings.AccessKey = "2qvZqxY40jmIKg5eLip0NCNd0pV4H3PDcPYuDA5M";
            //设置SK
            Settings.SecretKey = "9E7vAfkreDnXuhgfkW_OoeX5DY-bMzIVBPhv7Buo";
            try
            {
                Mac    mac      = new Mac(Settings.AccessKey, Settings.SecretKey);
                string suffixsl = fileName.Substring(fileName.LastIndexOf(".") + 1).ToLower();
                Random rd       = new Random();
                string newName  = Guid.NewGuid().ToString();
                //string saveKey = "qiniu" +rd.Next(100,999)+ DateTime.Now.ToString("yyyyMMddHHmmss") + "." + suffixsl;
                string saveKey = "qiniu" + rd.Next(100, 999) + newName + "." + suffixsl;
                BLL.Common.Logger.Info("saveKey:" + saveKey);
                //string allName = AppDomain.CurrentDomain.BaseDirectory + "/upload/" + newfileName + "." + suffixsl;
                //file.SaveAs(allName);
                string allName = "/UploadQiNiuFiles/" + saveKey;
                file.SaveAs(System.Web.HttpContext.Current.Server.MapPath(allName));
                // 本地文件路径
                string filePath = fileName;
                filePath = System.Web.HttpContext.Current.Server.MapPath("/UploadQiNiuFiles/" + saveKey);
                BLL.Common.Logger.Info("filePath:" + filePath);
                // filePath = "D:\\POS.jpg";
                // 存储空间名
                string Bucket = "pic-set";
                // 设置上传策略,详见:https://developer.qiniu.com/kodo/manual/1206/put-policy
                PutPolicy putPolicy = new PutPolicy();
                // 设置要上传的目标空间
                putPolicy.Scope = Bucket;
                // 上传策略的过期时间(单位:秒)
                putPolicy.SetExpires(3600);
                //// 文件上传完毕后,在多少天后自动被删除
                //putPolicy.DeleteAfterDays = 1;
                // 生成上传token
                string token = Auth.CreateUploadToken(mac, putPolicy.ToJsonString());
                BLL.Common.Logger.Info("token:" + token);
                Config config = new Config();
                // 设置上传区域
                config.Zone = Zone.ZONE_CN_East;
                // 设置 http 或者 https 上传
                config.UseHttps      = true;
                config.UseCdnDomains = true;
                config.ChunkSize     = ChunkUnit.U512K;
                // 表单上传
                FormUploader target = new FormUploader(config);
                HttpResult   result = target.UploadFile(filePath, saveKey, token, null);
                BLL.Common.Logger.Info("QiQiuUpFile,result.Code:" + result.Code);
                BLL.Common.Logger.Info("imgUrRL + saveKey01:" + imgUrRL + saveKey);
                if (result.Code == 200)
                {
                    upFileResult.FileName     = saveKey;
                    upFileResult.imgAllUrl    = imgUrRL + saveKey;
                    upFileResult.Result       = true;
                    upFileResult.ErrorMessage = "上传成功";
                }
                else
                {
                    upFileResult.Result       = false;
                    upFileResult.ErrorMessage = "上传失败请稍后重试!";
                }
                BLL.Common.Logger.Info("imgUrRL + saveKey:" + imgUrRL + saveKey);
                BLL.Common.Logger.Info("upFileResult:" + new JavaScriptSerializer().Serialize(upFileResult));
                DeleteFile(filePath);
                //context.Response.Write(new JavaScriptSerializer().Serialize(upFileResult));
                string imgurl = imgUrRL + saveKey;

                //imgurls += imgurl + ",";
                context.Response.Write(imgurl);
            }
            catch (Exception ex)
            {
                upFileResult.Result       = false;
                upFileResult.ErrorMessage = ex.Message;
                BLL.Common.Logger.Info("ex.Message:" + ex.Message);
                BLL.Common.Logger.Info("ex:" + ex);
            }
            //}
            //context.Response.Write(imgurls);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="input_name"></param>
        /// <param name="folder_path"></param>
        /// <param name="file_extension"></param>
        /// <param name="UploadSize"></param>
        /// <returns></returns>
        public static UpFileResult Upload(string input_name, string folder_path, string file_extension, int?UploadSize)
        {
            string UploadExtension = "png|jpg|gif|bmp|txt|doc|xls|rar|jpeg";

            if (!UploadSize.HasValue || UploadSize.ToInt32() <= 0)
            {
                UploadSize = 300;
            }
            ////保存的文件路径名
            //ArrayList returnfilename = new ArrayList();
            ////保存失败的描述信息
            //ArrayList returnerror = new ArrayList();
            ////上传文件是否为空
            //bool isEmpty = false;

            UpFileResult _UpFileResult = new UpFileResult();

            try
            {
                List <HttpPostedFile> fileList = new List <HttpPostedFile>();

                if (string.IsNullOrEmpty(input_name))
                {
                    for (int i = 0; i < HttpContext.Current.Request.Files.Count; i++)
                    {
                        fileList.Add(HttpContext.Current.Request.Files[i]);
                    }
                }
                else
                {
                    for (int i = 0; i < HttpContext.Current.Request.Files.Keys.Count; i++)
                    {
                        if (input_name == HttpContext.Current.Request.Files.Keys[i].ToString())
                        {
                            fileList.Add(HttpContext.Current.Request.Files[i]);
                        }
                    }
                }

                foreach (HttpPostedFile file in fileList)
                {
                    if (file == null || file.ContentLength == 0)
                    {
                        _UpFileResult.isEmpty = true;
                    }
                    else if (Convert.ToDouble(file.ContentLength) > Convert.ToDouble(UploadSize) * 1024 * 1024)
                    {
                        _UpFileResult.returnerror.Add(string.Format("文件不能大于 {0}M", UploadSize));
                    }
                    else
                    {
                        //当前格式
                        string Extension = System.IO.Path.GetExtension(file.FileName).Replace(".", "");

                        //判断格式
                        bool     isExtensionRight = false;
                        string[] Extensions       = UploadExtension.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
                        for (int i = 0; i < Extensions.Length; i++)
                        {
                            if (Extensions[i].Trim().ToLower() == Extension.ToLower())
                            {
                                isExtensionRight = true; break;
                            }
                        }

                        //格式正确
                        if (isExtensionRight)
                        {
                            string filename = DateTime.Now.ToString("yyyyMMddHHmmssffff") + DealMvc.Common.Net.MathRandom.RandomNumber(4).ToString() + "." + Extension;

                            string AllFolderPath = HttpContext.Current.Server.MapPath("~" + folder_path);
                            //string AllFolderPath = HttpContext.Current.Server.MapPath(folder_path);
                            if (!Directory.Exists(AllFolderPath))
                            {
                                Directory.CreateDirectory(AllFolderPath);
                            }

                            //保存文件
                            file.SaveAs(HttpContext.Current.Server.MapPath("~" + folder_path + filename));
                            //file.SaveAs(HttpContext.Current.Server.MapPath(folder_path + filename));
                            System.Threading.Thread.Sleep(10);

                            _UpFileResult.returnfilename.Add(folder_path + filename);
                        }
                        else
                        {
                            _UpFileResult.returnerror.Add(string.Format("格式不在允许的范围内,只允许格式为:{0}", UploadExtension));
                        }
                    }
                }
            }
            catch
            {
                _UpFileResult.returnerror.Add("上传文件出错");
            }

            //ArrayList output = new ArrayList();
            //output.Add(returnfilename);//在returnerror不为空的时候才能把此值当成正确的上传文件位置值
            //output.Add(returnerror);//上传出错描述信息,不为空表示上传存在问题
            //output.Add(isEmpty);//上传文件是否为空

            return(_UpFileResult);
        }
        public UpFileResult UpLoadFile(UpFile filedata)
        {
            FileStream fs = null;

            try
            {
                if (WcfServerManage.IsDebug)
                {
                    ShowHostMsg(Color.Black, DateTime.Now, "客户端[" + filedata.clientId + "]准备上传文件...");
                }

                UpFileResult result = new UpFileResult();
                if (!Directory.Exists(filebufferpath))
                {
                    Directory.CreateDirectory(filebufferpath);
                }

                string _filename = DateTime.Now.Ticks.ToString() + filedata.FileExt;//生成唯一文件名,防止文件名相同会覆盖
                fs = new FileStream(filebufferpath + _filename, FileMode.Create, FileAccess.Write);

                if (WcfServerManage.IsDebug)
                {
                    //获取进度
                    getupdownprogress(filedata.FileStream, filedata.FileSize, (delegate(int _num)
                    {
                        ShowHostMsg(Color.Black, DateTime.Now, "客户端[" + filedata.clientId + "]上传文件进度:%" + _num);
                    }));
                }
                //int oldprogressnum = 0;
                //int progressnum = 0;
                int bufferlen = 4096;
                int count     = 0;
                //long readnum = 0;
                byte[] buffer = new byte[bufferlen];
                while ((count = filedata.FileStream.Read(buffer, 0, bufferlen)) > 0)
                {
                    fs.Write(buffer, 0, count);
                    //readnum += count;
                    ////获取上传进度
                    //getprogress(filedata.FileSize, readnum, ref progressnum);
                    //if (oldprogressnum < progressnum)
                    //{
                    //    oldprogressnum = progressnum;
                    //    if (progressDic_Up.ContainsKey(filedata.UpKey))
                    //    {
                    //        progressDic_Up[filedata.UpKey] = progressnum;
                    //    }
                    //    else
                    //    {
                    //        progressDic_Up.Add(filedata.UpKey, progressnum);
                    //    }
                    //    if (WcfServerManage.IsDebug)
                    //    {
                    //        ShowHostMsg(Color.Black, DateTime.Now, "客户端[" + filedata.clientId + "]上传文件进度:%" + oldprogressnum);
                    //    }
                    //}
                }

                //清空缓冲区
                fs.Flush();
                //关闭流
                fs.Close();

                if (WcfServerManage.IsDebug)
                {
                    ShowHostMsg(Color.Green, DateTime.Now, "客户端[" + filedata.clientId + "]上传文件完成");
                }

                result.IsSuccess = true;
                result.Message   = _filename;//返回保存文件

                return(result);
            }
            catch (Exception err)
            {
                if (fs != null)
                {
                    fs.Flush();
                    fs.Close();
                }
                //记录错误日志
                EFWCoreLib.CoreFrame.EntLib.ZhyContainer.CreateException().HandleException(err, "HISPolicy");
                UpFileResult result = new UpFileResult();
                result.IsSuccess = false;
                return(result);
            }
        }