I am using webDAV and .Net 2.0 to gather information on an email account on a server running Exchange Server 2003. I have access to the uri which looks like this:
http://my.mailserver.com/exchange/user/Inbox/someImportantEmail.EML
I attempted to copy the file like so:
Dim uri As New Uri(uriNode.InnerText)
If uri.IsFile() Then
Dim fn As String = Path.GetFileName(uri.LocalPath)
System.IO.File.Copy(uri.LocalPath, "c:\" & fn)
End If
But uri.IsFile() is always returning false. One other thing I noted is that uri.Local path is
/exchange/user/Inbox/someImportantEmail.EML
I this part of my problem? How can I copy the .eml file from the exchange server to the local hard drive?
EDIT:
I have implemented AnthonyWJones suggestion
Dim cred As New System.Net.CredentialCache
cred.Add(uri, "BASIC", New System.Net.NetworkCredential(_username, _password, _domain))
Dim wc As New WebClient()
wc.Credentials = cred
wc.DownloadFile(uri, "c:\testEML.EML")
and while this does create the testEML.EML file on my c drive… here are the contents of the EML file:
<!--Copyright (c) 2000-2003 Microsoft Corporation. All rights reserved.-->
<!--CURRENT FILE== "NON-IE5" "NON-WIN32" frameset -->
<!--CURRENT TEMPLATE == frameset.00000000 -->
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=utf-8">
<TITLE>Microsoft Outlook Web Access</TITLE>
<BASE href="http://my.mailserver.com/exchange/user/">
</HEAD>
<SCRIPT language="JavaScript">
var g_iNewWindowWidth = 700;
var g_iNewWindowHeight = 500;
var g_fWarnOnLogOff=false;
function WarnOnLogOff()
{
if (g_fWarnOnLogOff)
alert("To help protect your mailbox from unauthorized access, close all browser windows when you finish using Outlook Web Access.");
}
</SCRIPT>
<FRAMESET OnUnload="WarnOnLogOff()" framespacing="3" cols="190,*"><FRAME bordercolor="#3D5FA3" name="navbar" title="Navigation" src="Inbox/?Cmd=navbar" marginheight="0" marginwidth="0" scrolling="auto" border="1"><FRAME name="viewer" title="Contents" src="Inbox/FW:.EML?Cmd=open" scrolling="auto">
<NOFRAMES>
<BODY><P>This page uses frames, but your browser doesn't support them.</P></BODY>
</NOFRAMES>
</FRAMESET>
</HTML>
What’s with the unauthorized access??
This is the code I ended up with that did exactly what I needed.