How to Cast from a System.DirectoryServices.PropertyValueCollection Value object to Byte[]  
Author Message
Dave_mnak





PostPosted: Visual C# General, How to Cast from a System.DirectoryServices.PropertyValueCollection Value object to Byte[] Top

Greetings, I'm pretty new to C#, so sorry if this is a dumb question. I am trying to read a byte field on a System.DirectoryServices.PropertyValueCollection which contains a jpeg image to an http response stream. I am getting hung up on my lack of type casting knowlege in C#, as I can do this very easily in VB. Please help:

DirectoryEntry entry = new DirectoryEntry("LDAP://DC=blah,DC=com");

DirectorySearcher mySearcher = new DirectorySearcher(entry);

mySearcher.Filter = ("(sAMAccountName=" + "blah" + ")");

SearchResult result = mySearcher.FindOne();

System.DirectoryServices.PropertyValueCollection props = result.GetDirectoryEntry().Properties["thumbnailPhoto"];

byte[] arraybytes = props[0]; // <--------This property should be an array of bytes, but this cast fails saying type object. What do I do




Visual C#20  
 
 
Dave_mnak





PostPosted: Visual C# General, How to Cast from a System.DirectoryServices.PropertyValueCollection Value object to Byte[] Top

Nevermind. Like I explained, I'm new to C# and hadn't touched C / C++ since college. So I got out my college C book. Corrected code is:

byte[] arraybytes = {byte[])props[0];