尝试创建"activitymimeattachment"时获取空的pdf附件. [英] Getting empty pdf attachments when trying to create "activitymimeattachment"

查看:50
本文介绍了尝试创建"activitymimeattachment"时获取空的pdf附件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将URL中的pdf附加到CRM"activitymimeattachment"中.一切正常,但是我得到的PDF附件为空(即使大小与原始pdf相同).编码或转换可能会出现问题吗?也许有人可以帮我这个忙吗?

I want to attach pdf from url into CRM "activitymimeattachment". Everything works fine but im getting empty pdf attachments (even the size is the same as original pdf). Could it be some problem with Encoding or converting? Maybe somebody could help me with this?

我看到创建的电子邮件带有空的附件,但是大小与原始pdf相同.

I see that email is created with attachment which is empty, but the size is the same as for original pdf.

Entity attachment = new Entity("activitymimeattachment");
attachment["subject"] = "Attachment";
string fileName = "Invoice.pdf";
attachment["filename"] = fileName;
WebClient wc = new WebClient();
string theTextFile = wc.DownloadString(url);
byte[] fileStream = Encoding.ASCII.GetBytes(theTextFile);
attachment["body"] = Convert.ToBase64String(fileStream);
attachment["mimetype"] = "application/pdf";
attachment["attachmentnumber"] = 1;
attachment["objectid"] = new EntityReference("email", emailguid);
attachment["objecttypecode"] = "email";
service.Create(attachment);

推荐答案

感谢@Aron的建议.我实际上找到了一个非常简单的解决方案.我只是使用了WebClient类中的另一种方法.我需要将DownloadString(url)方法更改为DownloadData(url)方法的主要内容:

Thank You for advice @Aron. I actually have found a solution which is very simnply. I just used another method from WebClient class. The main thing I needed to change DownloadString(url) method into DownloadData(url) method:

WebClient wc = new WebClient();
byte[] theTextFile = wc.DownloadData(url);
attachment["body"] = Convert.ToBase64String(theTextFile);enter code here

这篇关于尝试创建"activitymimeattachment"时获取空的pdf附件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆