Pregunta

Estoy utilizando WebDAV y .Net 2.0 para recopilar información sobre una cuenta de correo electrónico en un servidor que ejecuta Exchange Server 2003. Tengo acceso a la URI que se parece a esto:

http://my.mailserver.com/exchange/user/Inbox/someImportantEmail.EML

Me trató de copiar el archivo de esta manera:

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

Pero uri.IsFile () siempre devuelve falso. Otra cosa que he observado es que es camino uri.Local

/exchange/user/Inbox/someImportantEmail.EML

Me esta parte de mi problema? ¿Cómo puedo copiar el archivo .eml desde el servidor de intercambio en el disco duro local?
EDIT:
He implementado AnthonyWJones sugerencia

    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")

y si bien esto hace crear el archivo testEML.EML en mi disco c ... aquí están los contenidos del archivo EML:

<!--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>

¿Qué pasa con el acceso no autorizado ??

¿Fue útil?

Solución 2

Este es el código que terminó con que hicieron exactamente lo que necesitaba.

    Dim msgPath As String = message.Path
    Dim msgURI As String = message.URI
    Dim msgID As String = message.ID

    MyCredentialCache = New System.Net.CredentialCache()
    MyCredentialCache.Add(New System.Uri(_inboxPath), "BASIC", New System.Net.NetworkCredential(_username, _password, _domain))

    Dim request As WebRequest = WebRequest.Create(msgURI)
    request.Credentials = MyCredentialCache
    request.ContentType = "text/xml"
    request.Headers.Add("Translate", "f")
    Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)

    Dim file As FileStream = New FileStream(msgPath, FileMode.CreateNew)
    Dim stream As Stream = response.GetResponseStream()

    Dim buffer() As Byte = New Byte(4096) {}
    Dim len As Integer = stream.Read(buffer, 0, buffer.Length)

    While (len > 0)
        file.Write(buffer, 0, len)
        len = stream.Read(buffer, 0, buffer.Length)
    End While

    file.Close()
    stream.Close()

Otros consejos

Probar: -

 Dim webClient As New WebClient()
 webClient.UseDefaultCredentials = True
 webClient.DownloadFile(uri, fn)

No se puede utilizar el archivo IO estándar para copiar un recurso http

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top