mahendra2071987
Posts: 2
Joined: 21.Dec.2009
Status: offline
|
hi to all i want to add all the items to public folder of MSExchange through OWA usig HTTP but i m unable to add contacts,mails,appointments,etc to public folder code snippet of adding contact to public folder is as follows,,,, please reply as soon as possible its urgent,,,,, thanx in advance....... using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.IO; namespace PublicFolderContacts { class Program { static void Main(string[] args) { try { // TODO: Replace with the URL of an object on the computer that is running Exchange 2000. string sUri = "http://localhost/public/vimalcontacts/"; System.Uri myUri = new System.Uri(sUri); HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(myUri); string strXMLNSInfo; string strNameInfo; /* string strBusinessAddrInfo; string strHomeAddrInfo; string strOtherAddrInfo; string strMailAddrInfo; string strPhoneInfo; string strEmailInfo; string strOrganizationalInfo; string strPersonalInfo; string strCustomerInfo; string strFollowUpInfo; string strMiscInfo; string strUserFieldsInfo; */ // Specify the Namespaces to be used. strXMLNSInfo = "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:\">"; // 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 = "<c:givenName>vimal</c:givenName>" + "<c:middlename>kantilal</c:middlename>" + "<c:sn>raghwani</c:sn>" + "<c:cn>vimal kantilal raghwani</c:cn>" + "<mail:subject>vimal raghwani</mail:subject>" + "<c:fileas>raghwani, vimal</c:fileas>" + "<c:initials>JJD</c:initials>" + "<c:nickname>vim</c:nickname>" + "<c:personaltitle>Mrs.</c:personaltitle>" + "<c:namesuffix>Msc.tech</c:namesuffix>"; // Specify the Business Address Information. // (Street, PO Box, City, State, Postal Code, and Country) /* strBusinessAddrInfo = "<c:street>parth sarthi</c:street>" + "<c:postofficebox>PO Box 12345</c:postofficebox>" + "<c:l>pune</c:l>" + "<c:st>Maharashtra</c:st>" + "<c:postalcode>411038</c:postalcode>" + "<c:co>India</c:co>"; // Specify the Home Address Information. // (Street, PO Box, City, State, Postal Code, and Country) strHomeAddrInfo = "<c:homeStreet>sangvi</c:homeStreet>" + "<c:homepostofficebox>PO Box 54321</c:homepostofficebox>" + "<c:homeCity>pune</c:homeCity>" + "<c:homeState>maharashtra</c:homeState>" + "<c:homePostalCode>411027</c:homePostalCode>" + "<c:homeCountry>India</c:homeCountry>"; // Specify the Other Address Information. // (Street, PO Box, City, State, Postal Code, and Country) strOtherAddrInfo = "<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:othercountry>United States</c:othercountry>"; // Specify which address is the mailing address. // 0 = None, 1 = Home, 2 = Business, 3 = Other strMailAddrInfo = "<c:vimal@maildebuger.com>2</c:mahendra@maildebuger.com>"; // Specify phone 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 = "<c:telephoneNumber>020-27280359</c:telephoneNumber>" + "<c:telephonenumber2>020-27280359</c:telephonenumber2>" + "<c:facsimiletelephonenumber></c:facsimiletelephonenumber>" + "<c:homePhone></c:homePhone>" + "<c:homephone2></c:homephone2>" + "<c:homefax></c:homefax>" + "<c:otherTelephone></c:otherTelephone>" + "<c:otherfax>206-555-0112</c:otherfax>" + "<c:pager>425-555-0116</c:pager>" + "<c:mobile>425-555-0117</c:mobile>" + "<c:othermobile>206-555-0113</c:othermobile>" + "<c:internationalisdnnumber>425-555-0118</c:internationalisdnnumber>" + "<c:telexnumber>425-555-0119</c:telexnumber>" + "<c:ttytddphone>425-555-0120</c:ttytddphone>" + "<c:callbackphone>425-555-0121</c:callbackphone>"; // Specify the e-mail address information. strEmailInfo = "<mapi:email1addrtype>EX</mapi:email1addrtype>" + "<mapi:email1emailaddress>" + "/o=Microsoft/ou=First Administrative Group/cn=Recipients/cn=jdobney" + "</mapi:email1emailaddress>" + "<mapi:email1originaldisplayname>" + "JoLynn Dobney (Exchange)" + "</mapi:email1originaldisplayname>" + "<mapi:email2addrtype>SMTP</mapi:email2addrtype>" + "<mapi:email2emailaddress>" + "JoLynn.Dobney@example.com" + "</mapi:email2emailaddress>" + "<mapi:email2originaldisplayname>" + "JoLynn Dobney (SMTP)" + "</mapi:email2originaldisplayname>" + "<mapi:email3addrtype>X400</mapi:email3addrtype>" + "<mapi:email3emailaddress>" + "c=us;a= ; p=Microsoft; o=Exchange; s=Dobney; g=JoLynn; i=J;" + "</mapi:email3emailaddress>" + "<mapi:email3originaldisplayname>" + "JoLynn Dobney (X400)" + "</mapi:email3originaldisplayname>"; // Specify 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 = "<c:o>Fourth Coffee </c:o>" + "<c:organizationmainphone>425-555-0199</c:organizationmainphone>" + "<c:businesshomepage>http://www.fourthcoffee.com</c:businesshomepage>" + "<c:department>YYY</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:roomnumber>C-309</c:roomnumber>" + "<c:employeenumber>987654321</c:employeenumber>" + "<c:computernetworkname>jdobney</c:computernetworkname>" + "<c:profession>Software Designer</c:profession>"; // Specify personal information. // (Birthday, Anniversary, Spouse, Children, Gender, // Personal Home Page, Hobbies) strPersonalInfo = "<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:hobbies>Reading, lawn bowling</c:hobbies>"; // Specify customer related information. // (Customer ID, Account, Billing Information) strCustomerInfo = "<c:customerid>YYY</c:customerid>" + "<c:account>YYY</c:account>" + "<c:billinginformation>YYY</c:billinginformation>"; // Specify Follow Up/Reminder information. // (Reminder, Reminder Topic, Reminder Time, and other reminder information) strFollowUpInfo = "<mapi:reminderset>1</mapi:reminderset>" + "<mapi:request>Call</mapi:request>" + "<mapi:remindertime>2001-12-01T08:00:00Z</mapi:remindertime>" + "<mapi:remindernexttime>2001-12-01T08:00:00Z</mapi:remindernexttime>" + "<e:reply-by-iso>2001-12-01T08:00:00Z</e:reply-by-iso>"; // Specify miscellaneous information. // (Categories, Contacts, Mileage, FTP Site, Language, // Government ID, Location, Internet Free/Busy Address, // Sensitivity) strMiscInfo = "<e:keywords-utf8>" + "<x:v>Buddies</x:v><x:v>Engineers</x:v>" + "</e:keywords-utf8>" + "<mapi: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</cal:fburl>" + "<mapi:sensitivity>2</mapi:sensitivity>"; // Specify the User Field information. // (User Field 1, User Field 2, User Field 3, User Field 4) strUserFieldsInfo = "<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>"; */ string sQuery; sQuery = "<?xml version='1.0'?>" + "<g:propertyupdate>" + strXMLNSInfo + "<g:set>" + "<g:prop>" + "<g:contentclass>urn:content-classes:person</g:contentclass>" + "<e:outlookmessageclass>IPM.Contact</e:outlookmessageclass>" + strNameInfo /*+ strBusinessAddrInfo + strHomeAddrInfo +strOtherAddrInfo + strMailAddrInfo + strPhoneInfo + strEmailInfo + strOrganizationalInfo + strPersonalInfo + strCustomerInfo + strFollowUpInfo + strMiscInfo + strUserFieldsInfo */ + "</g:prop>" + "</g:set>" + "</g:propertyupdate>"; // Set the credentials. NetworkCredential myCred = new NetworkCredential("vimal", "Exchange_12345"); CredentialCache myCredentialCache = new CredentialCache(); myCredentialCache.Add(myUri, "basic", myCred); HttpWRequest.Credentials = myCredentialCache; // Set the headers. HttpWRequest.KeepAlive = false; HttpWRequest.Headers.Set("Pragma", "no-cache"); HttpWRequest.Headers.Set("Translate", "f"); HttpWRequest.ContentType = "text/xml"; HttpWRequest.ContentLength = sQuery.Length; //Set the request timeout to 5 minutes. HttpWRequest.Timeout = 300000; // set the request method HttpWRequest.Method = "PROPPATCH"; // Store the data in a byte array. byte[] ByteQuery = System.Text.Encoding.ASCII.GetBytes(sQuery); HttpWRequest.ContentLength = ByteQuery.Length; Stream QueryStream = HttpWRequest.GetRequestStream(); // write the data to be posted to the Request Stream QueryStream.Write(ByteQuery,0,ByteQuery.Length); QueryStream.Close(); // Send the request and get the response, HttpWebResponse HttpWResponse = (HttpWebResponse)HttpWRequest.GetResponse(); // Get the Status code int iStatCode = (int)HttpWResponse.StatusCode; string sStatus = iStatCode.ToString(); Console.WriteLine("Status Code: {0}", sStatus); // Get the request headers string sReqHeaders = HttpWRequest.Headers.ToString(); Console.WriteLine(sReqHeaders); // Read the Response Steam Stream strm = HttpWResponse.GetResponseStream(); StreamReader sr = new StreamReader(strm); string sText = sr.ReadToEnd(); Console.WriteLine("Response: {0}", sText); // Close the stream. strm.Close(); // Clean up myCred = null; myCredentialCache = null; HttpWRequest = null; HttpWResponse = null; QueryStream = null; strm = null; sr = null; } catch (Exception e) { Console.WriteLine("{0} Exception caught.", e); } } } }
|