Convert File property to byte[]

  • 27 November 2015
  • 2 replies
  • 3 views

Badge +4

Hello,

 

I have a custom made smartobject service that takes as input a document of the type File and sends it to a webservice that accepts a byte[]

 

I'm having trouble converting the File property to byte, I've tried converting the object (Serviceobject.Properties["Document"].Value) to byte, tried encoding it etc but the document that goes through the webservice is always corrupted.

 

Any help would be appreciated.


2 replies

Badge +9

What kind of file are you passing in?


 


try the following code?


 


byte[] bytes = System.IO.File.ReadAllBytes(filename);

https://msdn.microsoft.com/en-us/library/system.io.file.readallbytes.aspx

Badge +4

Solution for those who are interested:

 

var xml = ServiceObject.Properties["PropertyName"].Value.ToString();
var xdoc = XDocument.Parse(xml);
var element = from e in xdoc.Descendants("content") select e;

byte[] document = Convert.FromBase64String(element.First().Value);

 

Reply