I found this code online just to create an outlook calendar folder. The following code is throwing an error saying that the host name cannot be resolved. Not sure where to go from here. I konw what my exchange server address is, but can't get it to connect. Any suggestions?
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Net;
5 using System.IO;
6
7 namespace ExchangeFun
8 {
9 class Program
10 {
11 static void Main(string[] args)
12 {
13 try
14 {
15 String sUri = "http://MBX71.ad2.softcom.biz/exchange/chris whisenhunt/inbox";
16 Uri myUri = new Uri(sUri);
17 HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(myUri);
18
19 String sQuery = "<?xml version='1.0'?>" +
20 "<a:propertyupdate xmlns:a='DAV:' " +
21 "xmlns:ex='http://schemas.microsoft.com/exchange/'>" +
22 "<a:set><a:prop>" +
23 "<ex:outlookfolderclass>IPF.Appointment</ex:outlookfolderclass>" +
24 "</a:prop></a:set>" +
25 "</a:propertyupdate>";
26
27 String userName = "";
28 String password = "";
29 NetworkCredential networkCredential = new NetworkCredential(userName, password);
30 CredentialCache credentialCache = new CredentialCache();
31 credentialCache.Add(myUri, "Basic", networkCredential);
32 httpWebRequest.Credentials = credentialCache;
33
34 httpWebRequest.KeepAlive = false;
35 httpWebRequest.Headers.Set("Pragma", "no-cache");
36 httpWebRequest.ContentType = "text/xml";
37 httpWebRequest.ContentLength = sQuery.Length;
38
39 httpWebRequest.Timeout = 300000;
40 httpWebRequest.Method = "MKCOL";
41
42 byte[] byteQuery = Encoding.ASCII.GetBytes(sQuery);
43 httpWebRequest.ContentLength = byteQuery.Length;
44 Stream stream = httpWebRequest.GetRequestStream();
45 stream.Write(byteQuery, 0, byteQuery.Length);
46 stream.Close();
47
48 HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
49 String status = httpWebResponse.StatusCode.ToString();
50 Console.WriteLine("Status Code: {0}", status);
51 String reqHeaders = httpWebRequest.Headers.ToString();
52 Console.WriteLine(reqHeaders);
53
54 Stream stream2 = httpWebResponse.GetResponseStream();
55 StreamReader streamReader = new StreamReader(stream2);
56 String text = streamReader.ReadToEnd();
57 Console.WriteLine("Response: {0}", text);
58 streamReader.Close();
59
60 networkCredential = null;
61 credentialCache = null;
62 httpWebResponse = null;
63 httpWebRequest = null;
64 stream = null;
65 stream2 = null;
66 streamReader = null;
67 }
68 catch (Exception e)
69 {
70 Console.WriteLine("{0} Exception caught.", e);
71 Console.ReadLine();
72 }
73 }
74
75 static void Main(string[] args)
76 {
77
78 }
79 }
80 }
81
If my reply helps answer your question then please mark as answer.