/// <summary> /// 保存二进制流文件
/// </summary>
/// <param name="files">文件流数据</param>
/// <param name="systemCode">系统编号</param>
/// <param name="moduleName">模块名称</param>
/// <param name="fileName">文件名称</param>
/// <returns></returns>
public string SaveDocument(
byte[] files,
string systemCode,
string moduleName,
string fileName)
{
//获取配置文件中设置的保存
string f = System.Configuration.ConfigurationManager.AppSettings[
"SaveFilePath"];
//虚拟路径,保存地址
string savePath =
"\\文件交换\\" + systemCode +
"\\" + moduleName;
//组合地址,绝对地址
string FilePath = f + savePath;
if(!Directory.Exists(Path.GetDirectoryName(FilePath)))
{
//创建目录
Directory.CreateDirectory(Path.GetDirectoryName(FilePath));
}
//保存文件
FileStream fstream = File.Create(FilePath + fileName, files.Length);
//创建文件流
try {
fstream.Write(files,
0, files.Length);
//把二进制流数据写入文件
return "保存成功";
}
catch (Exception ex)
{
return "保存失败";
}
finally {
fstream.Close();
}
}