c# - Exchange Web Services - convert emailitem attachment from Base64 string to Byte gives error -


i trying read email item attachment using ews , save disk text file can used later on.

i getting error:

"the input not valid base-64 string contains non-base 64 character, more 2 padding characters, or non-white space character among padding characters. " 

here code:

directory.createdirectory(emailattachmentspath);  // put attachment contents stream. c:\dev\ewshelloworld emailattachmentspath = emailattachmentspath + "\\" + semailsubject+".txt";  //save disk  using (stream filetodisk = new filestream(emailattachmentspath, filemode.openorcreate, fileaccess.readwrite)) {     byte[] contentbytes = system.convert.frombase64string(itemattachment.tostring());      filetodisk.write(contentbytes, 0,contentbytes.length);     filetodisk.flush();     filetodisk.close(); }  

what best way please?

i want text of email in text file, , attachments in email saved disk (i can part think using filestream.

philip,

you not able use convert() method on itemattachment because not base64 encoded. item attachment has lot of properties item, , if understand request looking body of email.

the first thing want consider adding check see if itemattachment email message. if is, there couple of lines text of email body:

itemattachment.load(new propertyset(basepropertyset.firstclassproperties)); string bodytext = itemattachment.item.body.text; 

the first line load item , it's first class properties. second line text version of email body.

i hope helps. if resolve question, please mark post answered.

thanks,

--- bob ---


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -