hello friends.....
need ur help...
i m accessing public folder of MS Exchange via OWA
how to add mails,contacts,tasks,appointment programatically?
Right now m using HTTP for post items in public folder but there is some problem with URI....
code snipet of adding contact is as follow............
please reply as soon as possible....
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;
/
// 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:\">";
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

ersonaltitle>Mrs.</c

ersonaltitle>" +
"<c:namesuffix>Msc.tech</c:namesuffix>";
// Specify the Business Address Information.
// (Street, PO Box, City, State, Postal Code, and Country)
string sQuery;
sQuery = "<?xml version='1.0'?>" +
"<g

ropertyupdate>" + strXMLNSInfo +
"<g:set>" +
"<g

rop>" +
"<g:contentclass>urn:content-classes

erson</g:contentclass>" +
"<e

utlookmessageclass>IPM.Contact</e

utlookmessageclass>" +
strNameInfo /*+ strBusinessAddrInfo +
strHomeAddrInfo +strOtherAddrInfo +
strMailAddrInfo + strPhoneInfo +
strEmailInfo + strOrganizationalInfo +
strPersonalInfo + strCustomerInfo +
strFollowUpInfo + strMiscInfo +
strUserFieldsInfo */ +
"</g

rop>" +
"</g:set>" +
"</g

ropertyupdate>";
// 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);
}
}
}
}