473,323 Members | 1,550 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Creating a new contact in Exchange

How can I create a new contact in exchange server from a vb.net web
application?
Sep 26 '06 #1
1 3926
Hello Gerhard,

As for creating a new contact in exchange, based on my experience, there're
two possible appraoches:

1. use Outlook COM component to automate the create contact task

2. use exchange WebDav protocol to send http request to create contact

For your scenario, since you're developing in ASP.NET environment,
server-side COM automation is not recommended. I think you may consider
using HttpWebRequest component to send WebDav request to create contact
under a certain user's Contacts directory. Here is a KB article which
provide some code snippet on this:

#How to create a Contact item by using the HttpWebRequest class and the
HttpWebResponse class in Visual Basic .NET
http://support.microsoft.com/kb/314190/en-us

and below is my local test code (adjust according to the above kb article):

==========test code============
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
Dim text1 As String =
"http://exchange_server_name/Exchange/username/Contacts/new_contact_name.eml
"
Dim uri1 As New Uri(text1)
Dim request1 As HttpWebRequest =
DirectCast(WebRequest.Create(uri1), HttpWebRequest)
Dim text2 As String = "xmlns:g=""DAV:""
xmlns:c=""urn:schemas:contacts:""
xmlns:e=""http://schemas.microsoft.com/exchange/""
xmlns:mapi=""http://schemas.microsoft.com/mapi/"" xmlns:x=""xml:""
xmlns:cal=""urn:schemas:calendar:"" xmlns:mail=""urn:schemas:httpmail:"">"
Dim text3 As String =
"<c:givenName>JoLynn</c:givenName><c:middlename>Julie</c:middlename><c:sn>Do
bney</c:sn><c:cn>JoLynn J. Dobney</c:cn><mail:subject>JoLynn
Dobney</mail:subject><c:fileas>Dobney,
JoLynn</c:fileas><c:initials>JJD</c:initials><c:nickname>Jo</c:nickname><c:p
ersonaltitle>Mrs.</c:personaltitle><c:namesuffix>MCSD</c:namesuffix>"
Dim text4 As String = "<c:street>Business Address
Information</c:street><c:postofficebox>PO Box
12345</c:postofficebox><c:l>AnyTown</c:l><c:st>WA</c:st><c:postalcode>12345-
1234</c:postalcode><c:co>United States</c:co>"
Dim text5 As String = "<c:homeStreet>Home Address
Information</c:homeStreet><c:homepostofficebox>PO Box
54321</c:homepostofficebox><c:homeCity>SomeTown</c:homeCity><c:homeState>WA<
/c:homeState><c:homePostalCode>12345</c:homePostalCode><c:homeCountry>United
States</c:homeCountry>"
Dim text6 As String = "<c:otherstreet>Other Address
Information</c:otherstreet><c:otherpostofficebox>PO Box
98765</c:otherpostofficebox><c:othercity>SomeTown</c:othercity><c:otherstate
>FL</c:otherstate><c:otherpostalcode>56789</c:otherpostalcode><c:othercountr
y>United States</c:othercountry>"
Dim text7 As String =
"<c:mailingaddressid>2</c:mailingaddressid>"
Dim text8 As String =
"<c:telephoneNumber>425-555-0110</c:telephoneNumber><c:telephonenumber2>425-
555-0111</c:telephonenumber2><c:facsimiletelephonenumber>425-555-0112</c:fac
similetelephonenumber><c:homePhone>425-555-0113</c:homePhone><c:homephone2>4
25-555-0114</c:homephone2><c:homefax>425-555-0115</c:homefax><c:otherTelepho
ne>206-555-0111</c:otherTelephone><c:otherfax>206-555-0112</c:otherfax><c:pa
ger>425-555-0116</c:pager><c:mobile>425-555-0117</c:mobile><c:othermobile>20
6-555-0113</c:othermobile><c:internationalisdnnumber>425-555-0118</c:interna
tionalisdnnumber><c:telexnumber>425-555-0119</c:telexnumber><c:ttytddphone>4
25-555-0120</c:ttytddphone><c:callbackphone>425-555-0121</c:callbackphone>"
Dim text9 As String =
"<mapi:email1addrtype>EX</mapi:email1addrtype><mapi:email1emailaddress>/o=Mi
crosoft/ou=First Administrative
Group/cn=Recipients/cn=jdobney</mapi:email1emailaddress><mapi:email1original
displayname>JoLynn Dobney
(Exchange)</mapi:email1originaldisplayname><mapi:email2addrtyp e>SMTP</mapi:e
mail2addrtype><mapi:email2emailaddress>Jo********* **@example.com</mapi:email
2emailaddress><mapi:email2originaldisplayname>JoLy nn Dobney
(SMTP)</mapi:email2originaldisplayname><mapi:email3addrtyp e>X400</mapi:email
3addrtype><mapi:email3emailaddress>c=us;a= ; p=Microsoft; o=Exchange;
s=Dobney; g=JoLynn;
i=J;</mapi:email3emailaddress><mapi:email3originaldispla yname>JoLynn Dobney
(X400)</mapi:email3originaldisplayname>"
Dim text10 As String = "<c:o>Fourth Coffee
</c:o><c:organizationmainphone>425-555-0199</c:organizationmainphone><c:busi
nesshomepage>http://www.fourthcoffee.com</c:businesshomepage><c:department>Y
YY</c:department><c:title>Lead Software Design
Engineer</c:title><c:manager>Karan Khanna</c:manager><c:secretarycn>Ken
Myer</c:secretarycn><c:secretaryphone>425-555-0123</c:secretaryphone><c:room
number>C-309</c:roomnumber><c:employeenumber>987654321</c:employeenumber><c:
computernetworkname>jdobney</c:computernetworkname><c:profession>Software
Designer</c:profession>"
Dim text11 As String =
"<c:bday>1974-01-01T08:00:00Z</c:bday><c:weddinganniversary>1995-01-01T08:00
:00Z</c:weddinganniversary><c:spousecn>Barry
Johnson</c:spousecn><c:childrensnames><x:v>David Johnson</x:v><x:v>Willis
Johnson</x:v></c:childrensnames><c:gender>Male</c:gender><c:personalHomePage
>http://www.example.com/JoLynnDobney/default.htm</c:personalHomePage><c:hobb
ies>Reading, lawn bowling</c:hobbies>"
Dim text12 As String =
"<c:customerid>YYY</c:customerid><c:account>YYY</c:account><c:billinginforma
tion>YYY</c:billinginformation>"
Dim text13 As String =
"<mapi:reminderset>1</mapi:reminderset><mapi:request>Call</mapi:request><map
i:remindertime>2001-12-01T08:00:00Z</mapi:remindertime><mapi:remindernexttim
e>2001-12-01T08:00:00Z</mapi:remindernexttime><e:reply-by-iso>2001-12-01T08:
00:00Z</e:reply-by-iso>"
Dim text14 As String =
"<e:keywords-utf8><x:v>Buddies</x:v><x:v>Engineers</x:v></e:keywords-utf8><m
api:contacts><x:v>Brian Johnson</x:v></mapi:contacts><e:mileage>Rarely used
string
property</e:mileage><c:ftpsite>ftp://ftp.example.com/</c:ftpsite><c:language
>US
English</c:language><c:governmentid>000-00-0000</c:governmentid><c:location>
Nowhere
Land</c:location><cal:fburl>http://www.example.com/JoLynnDobney/freebusy</ca
l:fburl><mapi:sensitivity>2</mapi:sensitivity>"
Dim text15 As String = "<e:extensionattribute1>User Data
1</e:extensionattribute1><e:extensionattribute2>User Data
2</e:extensionattribute2><e:extensionattribute3>User Data
3</e:extensionattribute3><e:extensionattribute4>User Data
4</e:extensionattribute4>"
Dim text16 As String = String.Concat(New String() {"<?xml
version='1.0'?><g:propertyupdate ", text2,
"<g:set><g:prop><g:contentclass>urn:content-classes:person</g:contentclass><
e:outlookmessageclass>IPM.Contact</e:outlookmessageclass>", text3, text4,
text5, text6, text7, text8, text9, text10, text11, text12, text13, text14,
text15, "</g:prop></g:set></g:propertyupdate>"})
request1.Credentials = CredentialCache.DefaultCredentials
request1.KeepAlive = False
request1.Headers.Set("Pragma", "no-cache")
request1.Headers.Set("Translate", "f")
request1.ContentType = "text/xml"
request1.ContentLength = text16.Length
request1.Timeout = 300000
request1.Method = "PROPPATCH"
Dim buffer1 As Byte() = Encoding.ASCII.GetBytes(text16)
request1.ContentLength = buffer1.Length
Dim stream1 As Stream = request1.GetRequestStream
stream1.Write(buffer1, 0, buffer1.Length)
stream1.Close()
Dim response1 As HttpWebResponse =
DirectCast(request1.GetResponse, HttpWebResponse)
Dim text17 As String = response1.StatusCode.ToString
Me.textBox1.Text = (Me.textBox1.Text & ChrW(13) & ChrW(10) &
"Status Code: {0}" & text17)
Dim text18 As String = request1.Headers.ToString
Me.textBox1.Text = (Me.textBox1.Text & ChrW(13) & ChrW(10) &
"headers: " & text18)
Dim stream2 As Stream = response1.GetResponseStream
Dim text19 As String = New StreamReader(stream2).ReadToEnd
Me.textBox1.Text = (Me.textBox1.Text & ChrW(13) & ChrW(10) &
"Response: " & text19)
stream2.Close()
request1 = Nothing
response1 = Nothing
stream1 = Nothing
stream2 = Nothing
Catch exception1 As Exception
Me.textBox1.Text = ("Exception:" & ChrW(13) & ChrW(10) & " " &
exception1.ToString)
End Try
End Sub
========================================

And you can also find similar C# code in the below site:

#Visual C# .NET 2003 KB Article(s)
http://www.kbalertz.com/technology_213_4.aspx
Hope this also helps. If you have anything unclear, please feel free to let
me know.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 27 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Brian Henry | last post by:
Does anyone know of a way to pull my contact lists out of exchange server and into a VB.net application? or even a public contact list? Thanks! This is something I need really bad, any help would...
0
by: Yatendra Khandelwal | last post by:
hi, I am a newbie to this (exchange server and workflows) and I am trying to create a test workflow app using workflow designer (office developer) and exchange 2003. I have created a workflow...
1
by: Patrick | last post by:
I'm trying to create a link from Access 2003 to an Exchange 2000 Public Folder called "WMContacts" I choose File => Get External Data=> Link Tables. I choose Exchange() and the wizard give me the...
0
by: Manuel Krummenacher | last post by:
Hello! I'm trying to develop an application to manage email-forwardings on an Exchange 2000 Server. Forwardings to external Addresses are requiring a contact with an Exchange account. I can...
1
by: Kjell Wilhelmsen | last post by:
Hi ... I'm working on a program that's importing/exporting data between our Intranet and our ActiveDirectory and Exchange server. Does anybody out there know how to create a meeting in a users...
1
by: B. Zuidgeest | last post by:
I use C# to connect a database with student information directly to the Active Directory (2003). This means that as the student is enlisted an account and mailbox is created in the active...
0
by: Brian Henry | last post by:
I want to pull my contact list (personal one) from the exchange server into a local text file. I know how to write stuff into a text file, just getting it from an exchange server is my problem....
0
by: Suman | last post by:
Hello Group, I am relatively new to .NET. I am trying to create a user in AD and a corresponding email account in the exchange server from an ASP.NET, C# application. ...
7
by: Bucs44 | last post by:
I'm very green when it comes to writing code and I'm trying to create a menu bar and pull down menus. The menu bar contains three options: File, Edit and Help. The File menu contains four options:...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.