EWS C# Attachment Question RRS feed

  • Question

  • I am using the following code to get attachments from an email message. Thing is I have about six places in my overall code page that uses the same code.

    I don't now what to put in for the ???? from my EmailMessage mail statement.

    What should I put where I have EmailMessage m in the second statement.

    Thanks for the help.

    sqlattachments(????, Convert.ToInt32(ticketnumber), currenticket, ticketreceived);
    private void sqlattachments(EmailMessage m, int mticketid, string mticketstring, DateTime mreceived)
                foreach (Attachment attachment in m.Attachments)
                    if (attachment is FileAttachment)
                        FileAttachment fileAttachment = attachment as FileAttachment;
                        // Stream attachment contents into a file.
                        string filepath = "\\\\pacvsiis02\\c$\\inetpub\\tickets\\attachments\\" + mticketstring + "\\";
                        FileStream theStream = new FileStream(filepath + fileAttachment.Name, FileMode.OpenOrCreate, FileAccess.ReadWrite);

    Friday, October 31, 2014 12:40 PM

All replies

  • Your EmailMessage is a custom type from your project. If do not provide this class is impossible to understand your question and help. Please, paste class code.
    Friday, October 31, 2014 1:53 PM
  • This is what I am using.
    private void PollExchange()
                SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
                FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox,sf ,new ItemView(10));
                string content = string.Empty;
                foreach (Item item in findResults.Items)
                    EmailMessage email = EmailMessage.Bind(service, item.Id);

    Friday, October 31, 2014 2:07 PM
  • It's quite difficult to understand the question your asking

    EmailMessage is one the EWS Managed Types http://msdn.microsoft.com/en-us/library/office/dd633710(v=exchg.80).aspx the class reference is http://msdn.microsoft.com/en-us/library/office/microsoft.exchange.webservices.data.emailmessage(v=exchg.80).aspx .

    I'll take a guess that from

                    EmailMessage email = EmailMessage.Bind(service, item.Id);

    You method call would include

    sqlattachments(email, Convert.ToInt32(ticketnumber), currenticket, ticketreceived);


    Monday, November 3, 2014 3:27 AM