In the code window, replace all the code with the following:
using System;
using System.Net;
using System.IO;
namespace WebDavNET
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
static void Main(string[] args)
{
try
{
// TODO: Replace with the URL of an object on Exchange 2000.
string sUri = "http://ExchServer/Exchange/UserAlias/Inbox/Test.EML";
System.Uri myUri = new System.Uri(sUri);
HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(myUri);
string sQuery;
sQuery = "<?xml version='1.0'?>" +
"<a:propfind xmlns:a='DAV:' xmlns:m='urn:schemas:mailheader:'>" +
"<a:prop>" +
"<m:subject/>" +
"<a:isfolder/>" +
"<a:displayname/>" +
"<a:href/>" +
"</a:prop>" +
"</a:propfind>";
// Set credentials.
// TODO: Replace with appropriate user credentials.
NetworkCredential myCred = new NetworkCredential(@"DomainName\UserName", "UserPassword");
CredentialCache myCredentialCache = new CredentialCache();
myCredentialCache.Add(myUri, "Basic", myCred);
HttpWRequest.Credentials = myCredentialCache;
//Uncomment the following statement and comment the previous four statements if you
//use Integrated Windows authentication.
//httpWRequest.Credentials = CredentialCache.DefaultCredentials
//Note In Basic type authentication, the user name and password are sent as base64-encoded text, and it is
//easily decoded. Microsoft recommends that you use Basic instead of SSL to help protect the user name and password.
// Set headers.
HttpWRequest.KeepAlive = true; //this is the default
HttpWRequest.Headers.Set("Pragma", "no-cache");
HttpWRequest.Headers.Set("Translate", "f");
HttpWRequest.ContentType = "text/xml";
HttpWRequest.ContentLength = sQuery.Length;
//Set the request timeout to five minutes.
HttpWRequest.Timeout = 300000;
// set the request method
HttpWRequest.Method = "PROPFIND";
// 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 a 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 stream
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);
}
}
}
}
|