Surya sasidhar
Surya sasidhar

Reputation: 30313

Are there any Outlook Contacts Controls in ASP.NET?

How can I access Microsoft Outlook contacts using ASP.NET? Are there any controls that can do this?

Upvotes: 0

Views: 2506

Answers (3)

ScottE
ScottE

Reputation: 21630

If by control you mean api, there already is one - Exchange Web Services (EWS). Assuming you are dealing with exchange, and have EWS set up. The web services usually sit at:

https://[yourmaildomain.com]/EWS/Exchange.asmx

Here is some quick code - not production tested (also in vb.net)

Dim esb As New ExchangeServiceBinding()
esb.Credentials = New NetworkCredential("someusername", "somepassword")
esb.Url = "https://[yourmaildomain.com]/EWS/Exchange.asmx"

Dim addressType As New EmailAddressType()
With addressType
 .EmailAddress = "[email protected]"
 .MailboxType = MailboxTypeType.Mailbox
 .MailboxTypeSpecified = True
End With

' properties
Dim itemProperties As New ItemResponseShapeType()
itemProperties.BaseShape = DefaultShapeNamesType.AllProperties

' Identify which folders to search to find items.
Dim folderIDs(0) As DistinguishedFolderIdType

folderIDs(0) = New DistinguishedFolderIdType()
folderIDs(0).Id = DistinguishedFolderIdNameType.contacts
folderIDs(0).Mailbox = addressType


Dim findItemRequest As New FindItemType()
findItemRequest.Traversal = ItemQueryTraversalType.Shallow
findItemRequest.ItemShape = itemProperties
findItemRequest.ParentFolderIds = folderIDs

' send request
Dim findItemResponse As FindItemResponseType = esb.FindItem(findItemRequest)

Dim rmta As ResponseMessageType() = findItemResponse.ResponseMessages.Items
For Each rmt As ResponseMessageType In rmta
 If rmt.ResponseClass = ResponseClassType.Success Then

  Dim firmt As FindItemResponseMessageType = CType(rmt, FindItemResponseMessageType)
  If firmt IsNot Nothing Then

   Dim root As FindItemParentType = firmt.RootFolder
   Dim obj As Object = root.Item
   If TypeOf obj Is ArrayOfRealItemsType Then
    Dim items As ArrayOfRealItemsType = DirectCast(obj, ArrayOfRealItemsType)
    If items.Items IsNot Nothing Then
     For Each it As ItemType In items.Items
      If TypeOf it Is ContactItemType Then
       Dim cit As ContactItemType = DirectCast(it, ContactItemType)
       Response.Write("<p>")
       Response.Write(cit.Subject)
       Response.Write("<p>")
      End If
     Next
    End If
   End If

  End If

 End If
Next

Upvotes: 1

Shawn Steward
Shawn Steward

Reputation: 6825

You would need to create an ActiveX Application that the client would install to allow you access to this. Unless it's an internal development project, don't expect people to install something that gives you access to their email program.

Upvotes: 0

Related Questions