Microsoft KB Archive/296126

= How to create, modify, and delete contact items by using WebDAV (PROPPATCH) =

Article ID: 296126

Article Last Modified on 10/25/2007

-

APPLIES TO


 * Microsoft Exchange Server 2003 Standard Edition
 * Microsoft Exchange Server 2003 Enterprise Edition
 * Microsoft Exchange 2000 Server Standard Edition

-



This article was previously published under Q296126





SUMMARY
This step-by-step article discusses how to create or modify a contact item in Microsoft Exchange Server 2003 or in Microsoft Exchange 2000 Server by using the Web Distributed Authoring and Versioning (WebDAV) PROPPATCH method. This article also describes how to delete a contact by using the WebDAV DELETE method.

Code to create or modify a contact
The following Visual Basic Scripting Edition (VBScript) code sample creates a contact that is named John Doe. If this contact already exists, it will be modified. For demonstration purposes, this code sample sets most of the attributes that are available to contacts. Only the DAV:contentclass property and http://schemas.microsoft.com/exchange/outlookmessageclass are required.

Note To run this code sample, you must replace the following strings with the appropriate values wherever they exist in the code sample:

' Declare the variables that you will use. Dim objRequest 'As MSXML.XMLHTTPRequest Dim strBody 'As String Dim strXMLNSInfo 'As String Dim strNameInfo 'As String Dim strBusinessAddrInfo 'As String Dim strHomeAddrInfo 'As String Dim strOtherAddrInfo 'As String Dim strMailAddrInfo 'As String Dim strPhoneInfo 'As String Dim strEmailInfo 'As String Dim strOrganizationalInfo 'As String Dim strPersonalInfo 'As String Dim strCustomerInfo 'As String Dim strFollowUpInfo 'As String Dim strMiscInfo 'As String Dim strUserFieldsInfo 'As String Dim strURL 'As String ' Specify the URL of the new object that you will create. strURL = &quot;http://ServerName/Exchange/UserName/Contacts/John Doe.eml&quot; ' Create an HTTP request object. Set objRequest = CreateObject(&quot;Microsoft.xmlhttp&quot;) ' Specify the Namespaces that you will use. strXMLNSInfo = &quot;xmlns:g=&quot;&quot;DAV:&quot;&quot; &quot; & _ &quot;xmlns:c=&quot;&quot;urn:schemas:contacts:&quot;&quot; &quot; & _ &quot;xmlns:e=&quot;&quot;http://schemas.microsoft.com/exchange/&quot;&quot; &quot; & _ &quot;xmlns:mapi=&quot;&quot;http://schemas.microsoft.com/mapi/&quot;&quot; &quot; & _ &quot;xmlns:x=&quot;&quot;xml:&quot;&quot; xmlns:cal=&quot;&quot;urn:schemas:calendar:&quot;&quot; &quot; & _ &quot;xmlns:mail=&quot;&quot;urn:schemas:httpmail:&quot;&quot;>&quot; ' Specify the contact's name information. ' (First Name, Middle Name, Last Name, Full Name,   '  Subject of the contact--used by Outlook Address Book,    '  File As, Initials, Nickname, Title, and Suffix) strNameInfo = &quot;John&quot; & _ &quot;Jacob&quot; & _ &quot;Doe&quot; & _ &quot;John J. Doe&quot; & _ &quot;John Doe&quot; & _ &quot;Doe, John&quot; & _ &quot;JJD</c:initials>&quot; & _ &quot;<c:nickname>Johnnie</c:nickname>&quot; & _ &quot;<c:personaltitle>Mr.</c:personaltitle>&quot; & _ &quot;<c:namesuffix>MCSD</c:namesuffix>&quot; ' Specify the Business Address Information. ' (Street, PO Box, City, State, Postal Code, and Country) strBusinessAddrInfo = &quot;<c:street>One Microsoft Way</c:street>&quot; & _ &quot;<c:postofficebox>PO Box 12345</c:postofficebox>&quot; & _ &quot;<c:l>Redmond</c:l>&quot; & _ &quot;<c:st>WA</c:st>&quot; & _ &quot;<c:postalcode>98052-6399</c:postalcode>&quot; & _ &quot;<c:co>USA</c:co>&quot; ' Specify the Home Address Information. ' (Street, PO Box, City, State, Postal Code, and Country) strHomeAddrInfo = &quot;<c:homeStreet>500 Main Street</c:homeStreet>&quot; & _ &quot;<c:homepostofficebox>PO Box 54321</c:homepostofficebox>&quot; & _ &quot;<c:homeCity>Bellevue</c:homeCity>&quot; & _ &quot;<c:homeState>WA</c:homeState>&quot; & _ &quot;<c:homePostalCode>98004</c:homePostalCode>&quot; & _ &quot;<c:homeCountry>USA</c:homeCountry>&quot; ' Specify the Other Address Information. ' (Street, PO Box, City, State, Postal Code, and Country) strOtherAddrInfo = &quot;<c:otherstreet>99 Myrtle Ave</c:otherstreet>&quot; & _ &quot;<c:otherpostofficebox>PO Box 98765</c:otherpostofficebox>&quot; & _ &quot;<c:othercity>Green Cove Springs</c:othercity>&quot; & _ &quot;<c:otherstate>FL</c:otherstate>&quot; & _ &quot;<c:otherpostalcode>32043</c:otherpostalcode>&quot; & _ &quot;<c:othercountry>USA</c:othercountry>&quot; ' Specify which address is the mailing address. ' 0 = None, 1 = Home, 2 = Business, 3 = Other strMailAddrInfo = &quot;<c:mailingaddressid>2</c:mailingaddressid>&quot; ' Specify the telephone number information. ' (Business Phone, Business Phone 2, Business Fax,   '  Home Phone, Home Phone 2, Home Fax,    '  Other Phone, Other Fax, Pager, Mobile Phone,    '  Car Phone, ISDN, Telex, TTY/TDD, Callback) strPhoneInfo = &quot;<c:telephoneNumber>425-555-1110</c:telephoneNumber>&quot; & _ &quot;<c:telephonenumber2>425-555-1111</c:telephonenumber2>&quot; & _ &quot;<c:facsimiletelephonenumber>425-555-1112</c:facsimiletelephonenumber>&quot; & _ &quot;<c:homePhone>425-555-1113</c:homePhone>&quot; & _ &quot;<c:homephone2>425-555-1114</c:homephone2>&quot; & _ &quot;<c:homefax>425-555-1115</c:homefax>&quot; & _ &quot;<c:otherTelephone>904-555-1111</c:otherTelephone>&quot; & _ &quot;<c:otherfax>904-555-1112</c:otherfax>&quot; & _ &quot;<c:pager>425-555-1116</c:pager>&quot; & _ &quot;<c:mobile>425-555-1117</c:mobile>&quot; & _ &quot;<c:othermobile>904-555-1113</c:othermobile>&quot; & _ &quot;<c:internationalisdnnumber>425-555-1118</c:internationalisdnnumber>&quot; & _ &quot;<c:telexnumber>425-555-1119</c:telexnumber>&quot; & _ &quot;<c:ttytddphone>425-555-1120</c:ttytddphone>&quot; & _ &quot;<c:callbackphone>425-555-1121</c:callbackphone>&quot; ' Specify the e-mail address information. strEmailInfo = &quot;<mapi:emaillisttype>1</mapi:emaillisttype>&quot; & _ &quot;<mapi:email1addrtype>EX</mapi:email1addrtype>&quot; & _ &quot;<mapi:email1emailaddress>&quot; & _ &quot;/o=Microsoft/ou=First Administrative Group/cn=Recipients/cn=jdoe&quot; & _ &quot;</mapi:email1emailaddress>&quot; & _ &quot;<mapi:email1originaldisplayname>&quot; & _ &quot;John Doe (Exchange)&quot; & _ &quot;</mapi:email1originaldisplayname>&quot; & _ &quot;<mapi:email2addrtype>SMTP</mapi:email2addrtype>&quot; & _ &quot;<mapi:email2emailaddress>&quot; & _ &quot;john.doe@whatever.domain.com&quot; & _ &quot;</mapi:email2emailaddress>&quot; & _ &quot;<mapi:email2originaldisplayname>&quot; & _ &quot;John Doe (SMTP)&quot; & _ &quot;</mapi:email2originaldisplayname>&quot; & _ &quot;<mapi:email3addrtype>X400</mapi:email3addrtype>&quot; & _ &quot;<mapi:email3emailaddress>&quot; & _ &quot;c=us;a= ;p=Microsoft;o=Exchange;s=Doe;g=John;i=J;&quot; & _ &quot;</mapi:email3emailaddress>&quot; & _ &quot;<mapi:email3originaldisplayname>&quot; & _ &quot;John Doe (X400)&quot; & _ &quot;</mapi:email3originaldisplayname>&quot; ' Specify the organizational information. ' (Company, Company Main Phone, Business Home Page,   '  Department, Job Title, Manager's Name,    '  Assistant's Name, Assistant's Phone, Office Location,    '  Organizational ID Number, Computer Network Name,    '  Profession) strOrganizationalInfo = &quot;<c:o>Microsoft Corporation</c:o>&quot; & _ &quot;<c:organizationmainphone>425-882-8080</c:organizationmainphone>&quot; & _ &quot;<c:businesshomepage>http://www.microsoft.com</c:businesshomepage>&quot; & _ &quot;<c:department>YYY</c:department>&quot; & _ &quot;<c:title>Lead Software Design Engineer</c:title>&quot; & _ &quot;<c:manager>Ashley Doe</c:manager>&quot; & _ &quot;<c:secretarycn>Pat Doe</c:secretarycn>&quot; & _ &quot;<c:secretaryphone>425-555-1122</c:secretaryphone>&quot; & _ &quot;<c:roomnumber>C-309</c:roomnumber>&quot; & _ &quot;<c:employeenumber>987654321</c:employeenumber>&quot; & _ &quot;<c:computernetworkname>jdoe</c:computernetworkname>&quot; & _ &quot;<c:profession>Software Designer</c:profession>&quot; ' Specify the personal information. ' (Birthday, Anniversary, Spouse, Children, Gender,   '  Personal Home Page, Hobbies) strPersonalInfo = &quot;<c:bday>1974-01-01T08:00:00Z</c:bday>&quot; & _ &quot;<c:weddinganniversary>1995-01-01T08:00:00Z</c:weddinganniversary>&quot; & _ &quot;<c:spousecn>Jane Doe</c:spousecn>&quot; & _ &quot;<c:childrensnames>&quot; & _ &quot;<x:v>Ellen Doe</x:v><x:v>Grace Doe</x:v>&quot; & _ &quot;</c:childrensnames>&quot; & _ &quot;<c:gender>Male</c:gender>&quot; & _ &quot;<c:personalHomePage>&quot; & _ &quot;http://www.homepagedomain.com/JohnDoe/default.htm&quot; & _ &quot;</c:personalHomePage>&quot; & _ &quot;<c:hobbies>Playing XBox games,Watching UltimateTV</c:hobbies>&quot; ' Specify the customer-related information. ' (Customer ID, Account, Billing Information) strCustomerInfo = &quot;<c:customerid>YYY</c:customerid>&quot; & _ &quot;<c:account>YYY</c:account>&quot; & _ &quot;<c:billinginformation>YYY</c:billinginformation>&quot; ' Specify the Follow Up/Reminder information. ' (Reminder, Reminder Topic, Reminder Time, and so on.) strFollowUpInfo = &quot;<mapi:reminderset>1</mapi:reminderset>&quot; & _ &quot;<mapi:request>Call</mapi:request>&quot; & _ &quot;<mapi:remindertime>2001-12-01T08:00:00Z</mapi:remindertime>&quot; & _ &quot;<mapi:remindernexttime>2001-12-01T08:00:00Z</mapi:remindernexttime>&quot; & _ &quot;<e:reply-by-iso>2001-12-01T08:00:00Z</e:reply-by-iso>&quot; ' Specify any miscellaneous information. ' (Categories, Contacts, Mileage, FTP Site, Language,   '  Government ID, Location, Internet Free/Busy Address,    '  Sensitivity) strMiscInfo = &quot;<e:keywords-utf8>&quot; & _ &quot;<x:v>Buddies</x:v><x:v>Engineers</x:v>&quot; & _ &quot;</e:keywords-utf8>&quot; & _ &quot;<mapi:contacts><x:v>Penelope Doe</x:v></mapi:contacts>&quot; & _ &quot;<e:mileage>Rarely used string property</e:mileage>&quot; & _ &quot;<c:ftpsite>ftp://ftp.microsoft.com/</c:ftpsite>&quot; & _ &quot;<c:language>US English</c:language>&quot; & _ &quot;<c:governmentid>000-00-0000</c:governmentid>&quot; & _ &quot;<c:location>Nowhere Land</c:location>&quot; & _ &quot;<cal:fburl>http://www.homepagedomain.com/JohnDoe/freebusy</cal:fburl>&quot; & _ &quot;<mapi:sensitivity>2</mapi:sensitivity>&quot; ' Specify the User Field information. ' (User Field 1, User Field 2, User Field 3, User Field 4) strUserFieldsInfo = &quot;<e:extensionattribute1>User Data 1&quot; & _ &quot;</e:extensionattribute1>&quot; & _ &quot;<e:extensionattribute2>User Data 2</e:extensionattribute2>&quot; & _ &quot;<e:extensionattribute3>User Data 3</e:extensionattribute3>&quot; & _ &quot;<e:extensionattribute4>User Data 4</e:extensionattribute4>&quot; ' Put all the information together in an HTTP request. strBody = &quot;<?xml version=&quot;&quot;1.0&quot;&quot;?>&quot; & _ &quot;<g:propertyupdate &quot; & strXMLNSInfo & _ &quot;<g:set>&quot; & _ &quot;<g:prop>&quot; & _ &quot;<g:contentclass>urn:content-classes:person</g:contentclass>&quot; & _ &quot;<e:outlookmessageclass>IPM.Contact</e:outlookmessageclass>&quot; & _ strNameInfo & strBusinessAddrInfo & _ strHomeAddrInfo & strOtherAddrInfo & _ strMailAddrInfo & strPhoneInfo & _ strEmailInfo & strOrganizationalInfo & _ strPersonalInfo & strCustomerInfo & _ strFollowUpInfo & strMiscInfo & _ strUserFieldsInfo & _ &quot;</g:prop>&quot; & _ &quot;</g:set>&quot; & _ &quot;</g:propertyupdate>&quot; ' Open the request object and assign the PROPPATCH method to it. objRequest.open &quot;PROPPATCH&quot;, strURL, False, &quot;UserName&quot;, &quot;password&quot; ' Set the required headers for the request. objRequest.setRequestHeader &quot;Content-Type&quot;, &quot;text/xml&quot; objRequest.setRequestHeader &quot;Translate&quot;, &quot;f&quot; objRequest.setRequestHeader &quot;Content-Length&quot;, Len(strBody) ' Send the request. Use the XML document as the body. objRequest.send strBody 'Display the results. If (objRequest.Status >= 200 And objRequest.Status < 300) Then MsgBox &quot;Success! &quot; & &quot;Results = &quot; & objRequest.Status & _ &quot;: &quot; & objRequest.statusText ElseIf objRequest.Status = 401 Then MsgBox &quot;You do not have permission to do the job. &quot; & _ &quot;Please check your permissions on this item.&quot; Else MsgBox &quot;Request Failed. Results = &quot; & objRequest.Status & _ &quot;: &quot; & objRequest.statusText End If   Set objRequest = Nothing

Code to delete a contact
The following VBScript code sample deletes the contact that you created by using the previous code sample.

Note To run this code sample, you must replace the following strings with the appropriate values wherever they exist in the code sample:

' Declare the variables that you will use. Dim objRequest 'As MSXML.XMLHTTPRequest Dim strURL 'As String ' Specify the URL of the object that you will delete. strURL = &quot;http://ServerName/Exchange/UserName/Contacts/John Doe.eml&quot;

' Create an HTTP request object. Set objRequest = CreateObject(&quot;Microsoft.xmlhttp&quot;)

' Open the object and assign a method to the object. objRequest.open &quot;DELETE&quot;, strURL, False, &quot;UserName&quot;, &quot;password&quot; ' Send the request. Use the XML document as the body. objRequest.send 'Display the results. If (objRequest.Status >= 200 And objRequest.Status < 300) Then MsgBox &quot;Success! &quot; & &quot;Results = &quot; & objRequest.Status & _ &quot;: &quot; & objRequest.statusText ElseIf objRequest.Status = 401 Then MsgBox &quot;You do not have permission to do the job. &quot; & _ &quot;Please check your permissions on this item.&quot; Else MsgBox &quot;Request Failed. Results = &quot; & objRequest.Status & _ &quot;: &quot; & objRequest.statusText End If   Set objRequest = Nothing

Keywords: kbhowtomaster kbmsg KB296126

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.