【问题标题】:save attachment file in microsoft dynamic crm to computer将微软动态 crm 中的附件文件保存到计算机
【发布时间】:2012-06-23 08:21:22
【问题描述】:

CRM 将附件保存在 AnnotationBase 基表中。

如何将DocumentBody 实体中的文本转换回文件并将其保存到文件系统中?

我获得了documentbody 字段的值,然后尝试将其写入我的计算机,但我的文件已损坏。

我正在使用此代码:

String DocumentBody = Convert.ToBase64String(
      newUnicodeEncoding().GetBytes("UEsDBBQABgAIAAAAIQDQf9XuxAEAAE4HAAATAAgCW0NvbnRlbnRfVHlwZXNd       Lnh/abtPgp4eu7+W68C2dvLaWtho32sTajdkFmweGeKMQYTD5MrcDFf"));

using (FileStream fs = new FileStream("c:\\1.docx", FileMode.Create, FileAccess.Write))
{
    byte[] bytes = Convert.FromBase64String(DocumentBody);
    fs.Write(bytes, 0, bytes.Length);
}

GetBytes 中的字符串与 annotationBase 表中的documentbody 字段相同。

【问题讨论】:

  • 不明白为什么人们已经标记了这个问题。非常中肯。

标签: c# c#-4.0 dynamics-crm dynamics-crm-2011 dynamics-crm-4


【解决方案1】:

这是一直对我有用的代码 - 我可以确认这对我使用从 CRM 4 和 CRM 4 SDK 检索的数据有效。大约 18 个月前,我做了一个几乎完全相同的项目,我们必须归档所有来自 CRM 的笔记和电子邮件。

如果您仍有问题see the original source of this code

public static void ExportFile(string fileName, string content)
{
    byte[] fileContent = Convert.FromBase64String(content);
    using (FileStream file = new FileStream(fileName, FileMode.Create))
    {
        using (BinaryWriter writer = new BinaryWriter(file))
        {
            writer.Write(fileContent,0,fileContent.Length);
            writer.Close();
        }

        file.Close();
    }
}

【讨论】:

    猜你喜欢
    • 2015-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-06
    • 2016-11-09
    相关资源
    最近更新 更多