0

Working in vb.net within UiPath Studio, I have a mail attachment object (System.Net.Mail.Attachment). I want to directly convert the attachment to a Base64 string. Is there a way to accomplish this, perhaps by utilizing the ContentStream method?

caseodilla
  • 73
  • 1
  • 1
  • 6

1 Answers1

0

I managed to complete this using direct assignments. I'm working with an attachment object named Attachment. First, create the variables:

Stream as System.IO.Stream
Buffer as System.Byte[]
BufferLength as Int32

Then use an Assign activity for the following:

Stream = Attachment.ContentStream
Buffer = new Byte(Cint(Stream.Length)){}
BufferLength = Stream.Read(Buffer, 0, Buffer.Length)
File_Base64 = Convert.ToBase64String(Buffer)

The BufferLength assignment is a little hacky, but the Stream.Read method returns a value that is the length of the Read. That value isn't helpful for me, but to make this work in an Assign activity, I just accept the value in an integer variable.

caseodilla
  • 73
  • 1
  • 1
  • 6
  • 1
    This worked for me like a charm, but you have a couple of bugs: 1) Attachment.Name is not the correct property; you need Attachment.ContentStream. 2) BufferLength assignment has an extra ) at the end. – VictorEspina Jan 06 '23 at 01:21
  • Ah, what a terrible oversight! Thanks for catching and correcting it. I've updated my answer. – caseodilla Jan 07 '23 at 04:02