|
|
|
date: Wed, 21 Feb 2007 08:50:20 +1100,
group: microsoft.public.exchange2000.development
back
getting emails from webserver
Hi
I am a newbie with exchange2000 development. I get an error 404( server not
found) in the following code?
thanks
N
Option Explicit On
Option Strict On
Imports Microsoft.VisualBasic
Imports System
Imports System.Exception
Imports System.IO
Imports System.Net
Imports System.Web
Imports System.Web.UI
Imports System.Web.Caching
Imports System.Xml
Imports System.Reflection
Imports System.Xml.XPath
Imports System.Data.SqlClient
Module Module1
Sub Main()
' Variables.
Dim Request As System.Net.HttpWebRequest
Dim Response As System.Net.HttpWebResponse
Dim MyCredentialCache As System.Net.CredentialCache
Dim strPassword As String
Dim strDomain As String
Dim strUserName As String
Dim strSrcURI As String
Dim strBody As String
Dim bytes() As Byte
Dim RequestStream As System.IO.Stream
Dim ResponseStream As System.IO.Stream
Dim ResponseXmlDoc As System.Xml.XmlDocument
Dim DisplayNameNodes As System.Xml.XmlNodeList
Try
' Initialize variables.
strUserName = "UserName"
strPassword = "!Password"
strDomain = "Domain"
strSrcURI =
"http://www.microsoft.com/technet/community/newsgroups/dgbrowser/en-us/default.mspx?dg=microsoft.public.sharepoint.general"
' Build the PROPFIND request body.
strBody = "<?xml version=""1.0""?>" _
& "<d:propfind xmlns:d='DAV:'><d:prop>" _
& "<d:displayname/></d:prop></d:propfind>"
' Create a new CredentialCache object and fill it with the network
' credentials required to access the server.
MyCredentialCache = New System.Net.CredentialCache
MyCredentialCache.Add(New System.Uri(strSrcURI), _
"NTLM", _
New System.Net.NetworkCredential(strUserName, strPassword, strDomain) _
)
' Create the PUT HttpWebRequest object.
Request = CType(System.Net.WebRequest.Create(strSrcURI), _
System.Net.HttpWebRequest)
' Add the network credentials to the request.
'Request.Credentials = MyCredentialCache
Request.Credentials = CredentialCache.DefaultCredentials
' Specify the PROPFIND method.
Request.Method = "PROPFIND"
' Encode the body using UTF-8.
bytes = System.Text.Encoding.UTF8.GetBytes(strBody)
' Set the content header length. This must be
' done before writing data to the request stream.
Request.ContentLength = bytes.Length
' Get a reference to the request stream.
RequestStream = Request.GetRequestStream()
' Write the message body to the request stream.
RequestStream.Write(bytes, 0, bytes.Length)
' Close the Stream object to release the connection
' for further use.
RequestStream.Close()
' Set the Content Type header.
Request.ContentType = "text/xml"
' Set the Depth header.
Request.Headers.Add("Depth", "1")
' Set the Translate header.
Request.Headers.Add("Translate", "F")
' Send the PROPFIND method request and get the
' response from the server.
Response = CType(Request.GetResponse(), System.Net.HttpWebResponse)
' Get the XML response stream.
ResponseStream = Response.GetResponseStream()
' Create the XmlDocument object from the XML response stream.
ResponseXmlDoc = New System.Xml.XmlDocument
ResponseXmlDoc.Load(ResponseStream)
' Build a list of the DAV:href XML nodes, corresponding to the folders
' in the mailbox. The DAV: namespace is typically assgigned the a:
' prefix in the XML response body.
DisplayNameNodes = ResponseXmlDoc.GetElementsByTagName("a:displayname")
If DisplayNameNodes.Count > 0 Then
' Display the item's display name.
Console.WriteLine("DAV:displayname property...")
Console.WriteLine(DisplayNameNodes(0).InnerText)
Else
Console.WriteLine("DAV:displayname property not found...")
End If
' Clean up.
ResponseStream.Close()
Response.Close()
Catch ex As Exception
' Catch any exceptions. Any error codes from the
' PROPFIND method requests on the server will be caught
' here, also.
Console.WriteLine(ex.Message)
End Try
End Sub
End Module
date: Wed, 21 Feb 2007 08:50:20 +1100
author: Nick C
Re: getting emails from webserver
Hello,
I suppose you are not using the url you put in the code snippet you
provided.
If you can open the url in your browser, and OWA comes up with the contents
of the mail, you can use that url to get the properties you requested via
WebDAV.
Best regards,
Henning Krause
"Nick C" wrote in message
news:eu6E$jTVHHA.2256@TK2MSFTNGP02.phx.gbl...
> Hi
>
> I am a newbie with exchange2000 development. I get an error 404( server
> not found) in the following code?
>
> thanks
>
> N
>
> Option Explicit On
>
> Option Strict On
>
> Imports Microsoft.VisualBasic
>
> Imports System
>
> Imports System.Exception
>
> Imports System.IO
>
> Imports System.Net
>
> Imports System.Web
>
> Imports System.Web.UI
>
> Imports System.Web.Caching
>
> Imports System.Xml
>
> Imports System.Reflection
>
> Imports System.Xml.XPath
>
> Imports System.Data.SqlClient
>
> Module Module1
>
> Sub Main()
>
> ' Variables.
>
> Dim Request As System.Net.HttpWebRequest
>
> Dim Response As System.Net.HttpWebResponse
>
> Dim MyCredentialCache As System.Net.CredentialCache
>
> Dim strPassword As String
>
> Dim strDomain As String
>
> Dim strUserName As String
>
> Dim strSrcURI As String
>
> Dim strBody As String
>
> Dim bytes() As Byte
>
> Dim RequestStream As System.IO.Stream
>
> Dim ResponseStream As System.IO.Stream
>
> Dim ResponseXmlDoc As System.Xml.XmlDocument
>
> Dim DisplayNameNodes As System.Xml.XmlNodeList
>
> Try
>
> ' Initialize variables.
>
> strUserName = "UserName"
>
> strPassword = "!Password"
>
> strDomain = "Domain"
>
> strSrcURI =
> "http://www.microsoft.com/technet/community/newsgroups/dgbrowser/en-us/default.mspx?dg=microsoft.public.sharepoint.general"
>
> ' Build the PROPFIND request body.
>
> strBody = "<?xml version=""1.0""?>" _
>
> & "<d:propfind xmlns:d='DAV:'><d:prop>" _
>
> & "<d:displayname/></d:prop></d:propfind>"
>
> ' Create a new CredentialCache object and fill it with the network
>
> ' credentials required to access the server.
>
> MyCredentialCache = New System.Net.CredentialCache
>
> MyCredentialCache.Add(New System.Uri(strSrcURI), _
>
> "NTLM", _
>
> New System.Net.NetworkCredential(strUserName, strPassword, strDomain) _
>
> )
>
> ' Create the PUT HttpWebRequest object.
>
> Request = CType(System.Net.WebRequest.Create(strSrcURI), _
>
> System.Net.HttpWebRequest)
>
> ' Add the network credentials to the request.
>
> 'Request.Credentials = MyCredentialCache
>
> Request.Credentials = CredentialCache.DefaultCredentials
>
> ' Specify the PROPFIND method.
>
> Request.Method = "PROPFIND"
>
> ' Encode the body using UTF-8.
>
> bytes = System.Text.Encoding.UTF8.GetBytes(strBody)
>
> ' Set the content header length. This must be
>
> ' done before writing data to the request stream.
>
> Request.ContentLength = bytes.Length
>
> ' Get a reference to the request stream.
>
> RequestStream = Request.GetRequestStream()
>
> ' Write the message body to the request stream.
>
> RequestStream.Write(bytes, 0, bytes.Length)
>
> ' Close the Stream object to release the connection
>
> ' for further use.
>
> RequestStream.Close()
>
> ' Set the Content Type header.
>
> Request.ContentType = "text/xml"
>
> ' Set the Depth header.
>
> Request.Headers.Add("Depth", "1")
>
> ' Set the Translate header.
>
> Request.Headers.Add("Translate", "F")
>
> ' Send the PROPFIND method request and get the
>
> ' response from the server.
>
> Response = CType(Request.GetResponse(), System.Net.HttpWebResponse)
>
> ' Get the XML response stream.
>
> ResponseStream = Response.GetResponseStream()
>
> ' Create the XmlDocument object from the XML response stream.
>
> ResponseXmlDoc = New System.Xml.XmlDocument
>
> ResponseXmlDoc.Load(ResponseStream)
>
> ' Build a list of the DAV:href XML nodes, corresponding to the folders
>
> ' in the mailbox. The DAV: namespace is typically assgigned the a:
>
> ' prefix in the XML response body.
>
> DisplayNameNodes = ResponseXmlDoc.GetElementsByTagName("a:displayname")
>
> If DisplayNameNodes.Count > 0 Then
>
> ' Display the item's display name.
>
> Console.WriteLine("DAV:displayname property...")
>
> Console.WriteLine(DisplayNameNodes(0).InnerText)
>
> Else
>
> Console.WriteLine("DAV:displayname property not found...")
>
> End If
>
> ' Clean up.
>
> ResponseStream.Close()
>
> Response.Close()
>
> Catch ex As Exception
>
> ' Catch any exceptions. Any error codes from the
>
> ' PROPFIND method requests on the server will be caught
>
> ' here, also.
>
> Console.WriteLine(ex.Message)
>
> End Try
>
> End Sub
>
> End Module
>
>
date: Thu, 22 Feb 2007 23:39:04 +0100
author: Henning Krause [MVP - Exchange]
|
|