Thumbnailphoto property in Active Directory

M

MS Newsgroups

Hi,

I am trying to store a thumbnail picture in ActiveDirectory, but am having
some problems with type conversions.

According to the documentation the Thumbnailphoto property in the directory
is of typ OctetString, and i belive i read somewhere that i can use the
convert.ToBase64string function to convert a byte array to a octetstring.
This seem to be working since i can insert a image with the code:

Dim myEntry As New DirectoryEntry("LDAP://" & MyPath)
Dim myStream As New IO.FileStream("c:\myImage.jpg, IO.FileMode.Open)
Dim myByte() As Byte
ReDim myByte(CInt(myStream.Length))
myStream.Read(myByte, LBound(myByte), UBound(myByte) - 1)
MsgBox(myStream.Length)
myEntry.Properties("ThumbNailPhoto").Value =
Convert.ToBase64String(myByte)
myEntry.CommitChanges()

I am not sure that the data i am inputting here is valid, but i can see that
the property in the directory is being populated.

My real issue occurs when i try to retrieve the image back from the
directory, how do i convert the data back to a byte array ?

I have tried

Dim myEntry As New DirectoryEntry("LDAP://" & MyPath)

Dim myArr() As Byte
myArr = CType(myEntry.Properties("ThumbNailPhoto").Value, Byte())
Dim myStream As New IO.MemoryStream(myArr)
Dim myImage As Drawing.Image
PictureBox1.Image = MyImage.FromStream(myStream)

Which doesn not work, and when i check the .length property of the byte
array, it does not have the same size as it had when i input the data.
I have a feeling i need to convert the data from the directory before
puttimg it into the byte array, but i am a bit lost here.

If someone have some ideas on how to do this, I would appreciate it.

Many thanks

Niclas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top