?
Solved

Getting Images from AD

Posted on 2007-07-23
18
Medium Priority
?
476 Views
Last Modified: 2013-12-25
I want to the pull the images that are stored in AD under the photo attribute.  I have a query that is pulling it and I bound it using the asp:imagefield but it doesn't seem to be comming in.  On the records that have photos it will show a box with a red x - so it knows its there but it's just not comming through right.  

Does anyone know what the problem is?
0
Comment
Question by:scooter1977
  • 9
  • 9
18 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19550135
Are you pulling the jpegPhoto or thumbnailPhoto attribute from Active Directory?  How are you binding to the ImageField?

Bob
0
 

Author Comment

by:scooter1977
ID: 19550271
Pulling the thumbnailPhoto and I'm binding it in my gridview like this:    

<asp:ImageField DataImageUrlField="thumbnailPhoto">
           </asp:ImageField>
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19550303
I assume that you have a GridView.  How are you binding that?

Bob
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:scooter1977
ID: 19550521
Binding it to my gridview with an image field:    

<asp:ImageField DataImageUrlField="thumbnailPhoto">
           </asp:ImageField>
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19550605
>>Binding it
Binding what?

Bob
0
 

Author Comment

by:scooter1977
ID: 19551460
sorry ..... I'm pulling thumbnailphoto (along with some other things) from and LDAP query and I'm displaying the results in the gridview
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19556092
>>I'm pulling thumbnailphoto (along with some other things) from and LDAP query

How?

Bob
0
 

Author Comment

by:scooter1977
ID: 19556494
'Set up LDAP connection and search setting
        Dim AD As New DirectoryEntry("LDAP://OU=okc users, DC=ad,DC=osuokc,DC=edu ")
        Dim Searcher As New DirectorySearcher(AD)

        Searcher.Filter = ("(objectClass=user)")
        Searcher.Filter = ("(cn=" & StripUsr & ")")
        Searcher.SearchScope = 1
        Searcher.PropertiesToLoad.Add("givenname")
        Searcher.PropertiesToLoad.Add("sn")
        Searcher.PropertiesToLoad.Add("cn")
        Searcher.PropertiesToLoad.Add("department")
        Searcher.PropertiesToLoad.Add("mail")
        Searcher.PropertiesToLoad.Add("telephoneNumber")
        Searcher.PropertiesToLoad.Remove("ADsPath")
        Searcher.PropertiesToLoad.Add("wWWHomePage")



        Dim Results As SearchResultCollection
        Results = Searcher.FindAll()
        Dim result As SearchResult

        'Set up a data table to hold the info
        Dim myTable As New Data.DataTable("Results")
        Dim colName As String

        'iterate through each search property
        For Each colName In Searcher.PropertiesToLoad
            myTable.Columns.Add(colName, GetType(System.String))
        Next

        'add the results to the table
        For Each result In Results
            Dim dr As Data.DataRow = myTable.NewRow()

            For Each colName In Searcher.PropertiesToLoad

                If result.Properties.Contains(colName) Then
                    dr(colName) = CStr(result.Properties(colName)(0))
                Else
                    dr(colName) = ""
                End If

            Next
            myTable.Rows.Add(dr)
        Next

        'bind results to a gridview to easily manipulate look/feel of results
        Me.GridView1.DataSource = myTable
        Me.GridView1.ShowHeader = True
        Me.GridView1.AutoGenerateColumns = False
Me.GridView1.DataBind()
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19556539
I don't see 'thumbnailPhoto' in the PropertiesToLoad.

Bob

0
 

Author Comment

by:scooter1977
ID: 19558161
crap.... some days......I swear.... I have a local copy I'm working on and the working page is running on the web server.  I pasted the code from the server, not the one I have been modifying.  Here goes again.

    'Set up LDAP connection and search setting
        Dim AD As New DirectoryEntry("LDAP://OU=okc users, DC=ad,DC=osuokc,DC=edu ")
        Dim Searcher As New DirectorySearcher(AD)

        Searcher.Filter = ("(objectClass=user)")
        Searcher.SearchScope = 1
        Searcher.PropertiesToLoad.Add("givenname")
        Searcher.PropertiesToLoad.Add("sn")
        Searcher.PropertiesToLoad.Add("cn")
        Searcher.PropertiesToLoad.Add("department")
        Searcher.PropertiesToLoad.Add("mail")
        Searcher.PropertiesToLoad.Add("telephoneNumber")
        Searcher.PropertiesToLoad.Remove("ADsPath")
        Searcher.PropertiesToLoad.Add("wWWHomePage")
        Searcher.PropertiesToLoad.Add("thumbnailPhoto")



        Dim Results As SearchResultCollection
        Results = Searcher.FindAll()
        Dim result As SearchResult

        'Set up a data table to hold the info
        Dim myTable As New Data.DataTable("Results")
        Dim colName As String

        'iterate through each search property
        For Each colName In Searcher.PropertiesToLoad
            myTable.Columns.Add(colName, GetType(System.String))
        Next

        'add the results to the table
        For Each result In Results
            Dim dr As Data.DataRow = myTable.NewRow()

            For Each colName In Searcher.PropertiesToLoad

                If result.Properties.Contains(colName) Then
                    dr(colName) = result.Properties(colName)(0)
                Else
                    dr(colName) = ""
                End If

            Next
            myTable.Rows.Add(dr)
        Next

        'bind results to a gridview to easily manipulate look/feel of results
        Me.GridView1.DataSource = myTable
        Me.GridView1.ShowHeader = True
        Me.GridView1.AutoGenerateColumns = False
        Me.GridView1.DataBind()

and for the Gridview I have this:
 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
       <Columns>
           <asp:BoundField DataField="sn" HeaderText="Last" />
           <asp:BoundField DataField="givenname" HeaderText="First" />
           <asp:BoundField DataField="department" HeaderText="Department" />
           <asp:BoundField DataField="mail" HeaderText="email" />
           <asp:BoundField DataField="telephonenumber" HeaderText="Phone" />
           <asp:BoundField DataField="wwwhomepage" HeaderText="Web Page" />
           <asp:ImageField DataImageUrlField="thumbnailPhoto">
           </asp:ImageField>
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19558239
I believe the problem is that thumbnailPhoto is an OctetString.  I think that you can use Convert.FromBase64String to convert the value to an Image.

Bob
0
 

Author Comment

by:scooter1977
ID: 19559242
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19559262
First, what is the column data type for the photo column?

Bob
0
 

Author Comment

by:scooter1977
ID: 19559494
well here I'm pulling it in as a string :
  For Each colName In Searcher.PropertiesToLoad
            myTable.Columns.Add(colName, GetType(System.String))
        Next

I need to display it in jpg format

Is that what you need to know?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19559522
With the ImageField and the DataImageUrlField, the value needs to be a URL to image file that you want to display.

Bob
0
 

Author Comment

by:scooter1977
ID: 19559606
yeah, I went back and read   http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.imagefield.aspx   and realized that.  I originally thought that field would do the converting for me but I see that it will not.   Can I still display it in a regular databound column in my gridview or do I need to put it in some other type of control?
0
 

Author Comment

by:scooter1977
ID: 19559644
I don't care about pointing it to a url I just need to take it straight from the DB and convert it back to image and display it on the page
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 1500 total points
ID: 19560774
Read this, and see if using an HttpHandler will get you what you need:

Inserting Images into Database and Display it in GridView through Handler.ashx
http://www.aspdotnetcodes.com/Insert_Images_Database.aspx

Bob
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
By following these Magento e-commerce development tips, you can increase your website's conversion and profitability. Read this post for more details.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month8 days, 11 hours left to enroll

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question