Конвертировать документ Word с примечанием в PDF в CRM - PullRequest
0 голосов
/ 17 апреля 2020

Мне нужна твоя помощь. Я хочу преобразовать текстовый документ с примечанием в PDF и отправить его клиенту. Я получил вложение заметки с сущностью накладной, но не смог преобразовать ее в PDF. Пожалуйста, смотрите ниже код.

Entity emailCreated = service.Retrieve("email", SourceEmailID, new ColumnSet(true));
QueryExpression QueryNotes = new QueryExpression("annotation");
QueryNotes.ColumnSet = new ColumnSet(new string[] { "subject", "mimetype", "filename", "documentbody" });
QueryNotes.Criteria = new FilterExpression();
QueryNotes.Criteria.FilterOperator = LogicalOperator.And;
QueryNotes.Criteria.AddCondition(new ConditionExpression("objectid", ConditionOperator.Equal, invoiceID.Id));
EntityCollection MimeCollection = service.RetrieveMultiple(QueryNotes);
if (MimeCollection.Entities.Count > 0)
{ //we need to fetch first attachment
Entity NotesAttachment = MimeCollection.Entities.First();
//Create email attachment
Entity EmailAttachment = new Entity("activitymimeattachment");
if (NotesAttachment.Contains("subject"))
EmailAttachment["subject"] = NotesAttachment.GetAttributeValue<string>("subject");
EmailAttachment["objectid"] = new EntityReference("email", emailCreated.Id);
EmailAttachment["objecttypecode"] = "email";
if (NotesAttachment.Contains("filename"))
EmailAttachment["filename"] = NotesAttachment.GetAttributeValue<string>("filename");
if (NotesAttachment.Contains("documentbody"))
EmailAttachment["body"] = NotesAttachment.GetAttributeValue<string>("documentbody");
if (NotesAttachment.Contains("mimetype"))
EmailAttachment["mimetype"] = NotesAttachment.GetAttributeValue<string>("mimetype");

service.Create(EmailAttachment);
}
// Sending email
SendEmailRequest SendEmail = new SendEmailRequest();
SendEmail.EmailId = emailCreated.Id;
SendEmail.TrackingToken = "";
SendEmail.IssueSend = true;
SendEmailResponse res = (SendEmailResponse)service.Execute(SendEmail);

1 Ответ

0 голосов
/ 20 апреля 2020

Я изменяю только несколько строк, поскольку, имя файла в этом случае - stati c, но вы можете изменить его позже.

if (NotesAttachment.Contains("filename"))
EmailAttachment["filename"] = "abc.pdf";
if (NotesAttachment.Contains("documentbody"))
EmailAttachment["body"] = Convert.ToBase64String(NotesAttachment.GetAttributeValue<string>("documentbody"));
if (NotesAttachment.Contains("mimetype"))
EmailAttachment["mimetype"] = "text/plain";

Попробуйте следующий код,

Entity emailCreated = service.Retrieve("email", SourceEmailID, new ColumnSet(true));
    QueryExpression QueryNotes = new QueryExpression("annotation");
    QueryNotes.ColumnSet = new ColumnSet(new string[] { "subject", "mimetype", "filename", "documentbody" });
    QueryNotes.Criteria = new FilterExpression();
    QueryNotes.Criteria.FilterOperator = LogicalOperator.And;
    QueryNotes.Criteria.AddCondition(new ConditionExpression("objectid", ConditionOperator.Equal, invoiceID.Id));
    EntityCollection MimeCollection = service.RetrieveMultiple(QueryNotes);
    if (MimeCollection.Entities.Count > 0)
    { //we need to fetch first attachment
    Entity NotesAttachment = MimeCollection.Entities.First();
    //Create email attachment
    Entity EmailAttachment = new Entity("activitymimeattachment");
    if (NotesAttachment.Contains("subject"))
    EmailAttachment["subject"] = NotesAttachment.GetAttributeValue<string>("subject");
    EmailAttachment["objectid"] = new EntityReference("email", emailCreated.Id);
    EmailAttachment["objecttypecode"] = "email";
    if (NotesAttachment.Contains("filename"))
    EmailAttachment["filename"] = "abc.pdf";
    if (NotesAttachment.Contains("documentbody"))
    EmailAttachment["body"] = Convert.ToBase64String(NotesAttachment.GetAttributeValue<string>("documentbody"));
    if (NotesAttachment.Contains("mimetype"))
    EmailAttachment["mimetype"] = "text/plain";

    service.Create(EmailAttachment);
    }
    // Sending email
    SendEmailRequest SendEmail = new SendEmailRequest();
    SendEmail.EmailId = emailCreated.Id;
    SendEmail.TrackingToken = "";
    SendEmail.IssueSend = true;
    SendEmailResponse res = (SendEmailResponse)service.Execute(SendEmail);
...