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); }
/// <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); } }