繁体   English   中英

在.NET的Force.com工具包中使用ForceClient保存pdf附件

[英]using ForceClient in Force.com Toolkit for .NET to save a pdf attachment

我的附件已保存在线索中,但问题是它不会打开。

     private string GetFileAsStringBase64(Stream stream)
        {
            var data =  new StreamReader(stream).ReadToEnd();
            var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(data);
            var finalData = System.Convert.ToBase64String(plainTextBytes);
            var response = await client.CreateAsync("Attachment", new Attachment { Body = finalData , Name = _model.DirectorInformation.Attachment.FileName, ParentId = _model.LeadId });
        }
  public class Attachment
    {
        public string Body { get; set; }
        public string Name { get; set; }
        public string ParentId { get; set; }
    }

问题是字符串数据没有正确编码为base64string。 下面的代码将按Salesforce的要求将其转换为base64字符串。

            System.IO.BinaryReader br = new System.IO.BinaryReader(stream);
            Byte[] bytes = br.ReadBytes((Int32)stream.Length);
            string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
            return base64String;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM