Extract text data from Outlook user properties to my textbox 'winform' ... VB.net 2003

HI Experts,

Is it possible to extract data from Outlook? Users are AD domain members at work and usually logon with a unique username. This username is displayed within Outlook user properties. I would like to extract data (in text) and copy to my winform textbox.

Please see Attached Image below. So, for example, I would like to extract the (Department) data... by clicking a button on my winform....

Is there any easy solutions for this please?


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try the following:
Under the references for your applicaiton add the .NET reference to:
Under your projects AssemblyInfo.vb file add:
    Imports System.DirectoryServices
Assuming that your form has a textbox object named TextBox1 and a button object named Button1 (you can change the references of TextBox1 and Button1 to whatever your objects are named), the following code on the click event of the button should bring in the information you are looking for:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    'change reference from Button1 to whatever you've named your button object

        Dim objRoot As New DirectoryServices.DirectoryEntry("LDAP://rootDSE")
        Dim objDE As New DirectoryServices.DirectoryEntry(("LDAP://CN=Users," & objRoot.Properties("defaultNamingContext").Value).ToString)
        Dim objDS As New DirectoryServices.DirectorySearcher(objDE)

        objDS.SearchScope = DirectoryServices.SearchScope.Subtree
        objDS.Filter = "(&(objectClass=user)(sAMAccountName=" & Environment.UserName.ToString & "))"

        Dim objRecord As DirectoryServices.SearchResult = objDS.FindOne()

        'change reference from TextBox1 to whatever you've named your textbox object
        TextBox1.Text = objRecord.Properties("DisplayName").Item(0)

    End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sorry, line 14 of the above code should be:
        TextBox1.Text = objRecord.Properties("Department").Item(0)

Open in new window

RobertoFreemanoAuthor Commented:
Thanks irudyk,

I will test this out in work next Tue (as it's Easter Hols) in the UK.

Will keep you updated ;)

The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Just curious if you had any luck with the above code?
RobertoFreemanoAuthor Commented:
oops - Sorry irudyk,

I will test this tomorrow (in work)....
RobertoFreemanoAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.