2012-06-23 36 views
0

CRM將附件保存在AnnotationBase基本表中。將附件文件保存在Microsoft Dynamics CRM的計算機上

如何將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場。

+0

不明白爲什麼人們已經下調的問題。這非常恰當。 –

回答

1

下面是一直對我有效的代碼 - 我可以證實這一點對於我使用CRM 4 SDK中的CRM 4所獲取的數據有效。 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(); 
    } 
} 
相關問題