/// <summary>
/// 上传附件
/// </summary>
/// <param name="organizationService">CRM组织服务</param>
/// <param name="entityname">实体名称</param>
/// <param name="entityid">实体ID</param>
/// <param name="filename">文件名称</param>
/// <param name="filecontent">文件base64</param>
/// <param name="type">文件类型</param>
/// <param name="file_desc">文件描述</param>
/// <returns></returns>
public bool fileupload(IOrganizationService organizationService, string entityname, string entityid, string filename, string filecontent, string type, string file_desc)
{
try
{
WriteLog("上传文件begin!");
string filenewdocumentbody = filecontent;
string filepath = '\\' + entityname + '\\' + entityid;
string rootPath = GetSystemParameter( "GetFilePath",organizationService);//获取文件上传的根路径
string serverFilePath = rootPath + "\\" + filepath;
string serverFileName = rootPath + "\\" + filepath + "\\" + filename;
if (!Directory.Exists(serverFilePath))
Directory.CreateDirectory(serverFilePath);
FileStream fs = new FileStream(serverFileName, FileMode.Create, FileAccess.Write);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(Convert.FromBase64String(filenewdocumentbody));
bw.Close();
fs.Close();
WriteLog("上传文件Over!");
return true;
}
catch (Exception e)
{
throw new Exception(e.Message);
}
}
简单的文件上传工具类
最新推荐文章于 2024-07-24 09:00:46 发布