从 CRM Notes C# 将文档正文上传到 SharePoint

Uploading document body to SharePoint from CRM Notes C#

我可以上传文档,但是当我 viewing/downloading 时,似乎出现错误。它说 运行 打开此 PDF 时出现问题。 Ran into a problem

我有以下代码

using (var stream = new System.IO.MemoryStream())
{
    byte[] myByte = System.Text.ASCIIEncoding.Default.GetBytes(documentBody);
    foreach (byte element in myByte)
    {
        stream.WriteByte(element);
    }
    stream.Seek(0, SeekOrigin.Begin);
    var newFile = new FileCreationInformation { Url = fileName, ContentStream = stream, Overwrite = true };

    file = list.RootFolder.Files.Add(newFile);
    file.CheckOut();
    file.CheckIn(string.Empty, CheckinType.MajorCheckIn);
    context.Load(file);
    context.ExecuteQuery();
}

documentBodyAnnotation 中的字段 documentbody(注)。 stream 有问题吗?

documentBody 在 CRM 中采用 Base64 编码,因此您需要先对其进行解码,然后再保存到 SharePoint。

试试这个来获取文档数据。

byte[] data = Convert.FromBase64String(e.Attributes["documentbody"].ToString());