• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 877
  • Last Modified:

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?

Cheers,
Roberto

outlook-details.JPG
0
RobertoFreemano
Asked:
RobertoFreemano
  • 3
  • 3
1 Solution
 
irudykCommented:
Try the following:
Under the references for your applicaiton add the .NET reference to:
     System.DirectoryServices
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

0
 
irudykCommented:
Sorry, line 14 of the above code should be:
        TextBox1.Text = objRecord.Properties("Department").Item(0)

Open in new window

0
 
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 ;)

Cheers,
Rob
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

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

I will test this tomorrow (in work)....
0
 
RobertoFreemanoAuthor Commented:
:0
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now