473,498 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WebDAV download attachments

Hi,
I have two questions:
1) If there are more than one attachments, can I still use
urn:schema:httpmail:attachmentfilename to get the file names? How?
Or I need to use X-MS-ENUMATTS method?

2) After I get the filenames of the attachments, how do I download them to a
local folder?

Thanks in advance.

Li

Jul 21 '05 #1
4 6409
Hi Li,

We have reviewed this issue and are currently researching on it. We will
update you ASAP. Thanks for your patience!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #2
Hi Li,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to know how to download
attachments using WebDAV. If there is any misunderstanding, please feel
free to let me know.

We can use X-MS-ENUMATTS to go through the attachment list. Use a GET to
extract the stream, which can be save to file.

Here I found a sample:

' VB Example on enumerating and reading attatchments

' TODO: Add a reference to MS XML 4.0.

' TODO: Add a command button (cmdGetAttachmentsList) to a form.

' TODO: Add a multiline text box (txtResponse) with scroll bars to the
form.

' TODO: Change code as per TODO under the command button.

' TODO: Do the TODO sections at the bottom of this document which involve
creating a class.

'

' Also please review the following article, which shows some differences
to note for .NET:

' Managing Microsoft Exchange 2000 Calendars with XML Web Services

'
http://msdn.microsoft.com/library/de...us/dnmes2k/htm
l/calwp_0001.asp

'

Private Sub cmdGetAttachmentsList_Click()

Dim sUserName As String ' Domain/Username for server

Dim sPassword As String ' User's password

Dim sBaseURL As String

Dim sMessage As String

Dim sAttatch As String

Dim sXML As String

Dim aList As Collection

Dim anInst As CAttatchmentList

Dim sOutput As String

txtResponse.Text = ""

' TODO: Change the next four lines to match your user, password and
email

sUserName = "myuser" ' User

sPassword = "mypassword" ' Password

sBaseURL =
"http://myserver.mycompany.com/exchange/Administrator/Inbox/" ' Location of
email.

sMessage = "Test%20Attatch.EML" ' HREF of email I'm going to read

sXML = GetAttachmentsListXML(sBaseURL & sMessage, sUserName, sPassword)

sOutput = "-------------------------------------------------" & vbCrLf
& _

"The XML response:" & vbCrLf & vbCrLf & sXML & vbCrLf &
vbCrLf

Set aList = ParseAttatchmentListXML(sXML)

For Each anInst In aList

sOutput = sOutput &
"-------------------------------------------------" & vbCrLf

sOutput = sOutput & "******* Attatchment: " & anInst.href & vbCrLf

sOutput = sOutput & " attachmentfilename: " &
anInst.attachmentfilename & vbCrLf

sOutput = sOutput & " cn: " & anInst.cn & vbCrLf

sOutput = sOutput & " Attatchment Text: " & vbCrLf

sOutput = sOutput & ReadAnAttatchment(anInst.href, sUserName,
sPassword)

sOutput = sOutput & vbCrLf

Next

Set aList = Nothing

txtResponse.Text = sOutput

End Sub

'---------------------------------------------------------------------------

' GetAttachmentsListXML

' Searches an HREF to an email to find attatchments for the email

' Input

' sHREF - Http reference to the email

' sUserName - Domain/Username for server

' sPassword - Password for the account above

' Returns: An XML document resulting from the search

'---------------------------------------------------------------------------

Function GetAttachmentsListXML(ByVal sHREF As String, ByVal sUserName As
String, ByVal sPassword As String) As String

Const FOLDERITEM = "Inbox/Test1.eml"

Dim HttpWebRequest As Msxml2.XMLHTTP30

Dim strPropReq As String

Dim strOutPutFile As String

Set HttpWebRequest = New Msxml2.XMLHTTP30

With HttpWebRequest

.Open "X-MS-ENUMATTS", sHREF, False, sUserName, sPassword

.setRequestHeader "Content-type:", "text/xml"

.setRequestHeader "Depth", "1,noroot"

.Send

GetAttachmentsListXML = HttpWebRequest.ResponseText

End With

Set HttpWebRequest = Nothing

End Function

'---------------------------------------------------------------------------

' ReadAnAttatchment

' Reads the contents of an attatchment for an email.

' Input

' sHREF - Http reference to the email

' sUserName - Domain/Username for server

' sPassword - Password for the account above

' Returns: The contents of the email attatchment

'---------------------------------------------------------------------------

Private Function ReadAnAttatchment(ByVal sHREF As String, ByVal sUserName
As String, ByVal sPassword As String) As Variant

Dim HttpWebRequest As Msxml2.XMLHTTP30

Dim vReturn As Variant

Set HttpWebRequest = New Msxml2.XMLHTTP30

HttpWebRequest.Open "GET", sHREF, False, sUserName, sPassword

HttpWebRequest.Send

ReadAnAttatchment = HttpWebRequest.ResponseText ' Returns as text

'ReadAnAttatchment = HttpWebRequest.responseBody ' Returns as encoded

Set HttpWebRequest = Nothing

End Function

'---------------------------------------------------------------------------

' ParseAttatchmentListXML

' This will parse the XML document containing the list Attatchment names

' Input:

' sXML - An XML document string containing a list of email attatchments

' Returns:

' A collection of Email attatchemnt references (collection of
CAttatchmentList classes)

'---------------------------------------------------------------------------

Private Function ParseAttatchmentListXML(ByVal sXML As String) As Collection

Dim doc As Msxml2.DOMDocument

Set doc = New Msxml2.DOMDocument

Dim aNode As IXMLDOMNode

Dim aSecondNode As IXMLDOMNode

Dim aThirdNode As IXMLDOMNode

Dim aFourthNode As IXMLDOMNode

Dim aFifthNode As IXMLDOMNode

Dim sHREF As String

Dim sAttachmentFileName As String

Dim sCN As String

Dim lListCount As Long

lListCount = 1

sHREF = ""

sAttachmentFileName = ""

sCN = ""

Dim xmlRoot As IXMLDOMElement

Dim xmlNode As IXMLDOMNode

Dim xmlReq As Msxml2.XMLHTTP40

Dim objNodeList As IXMLDOMNodeList

Dim anInstance As New CAttatchmentList

Dim MyClasses As New Collection ' Create a Collection object.

doc.loadXML (sXML)

Set xmlRoot = doc.documentElement '.documentElemen

Set objNodeList = xmlRoot.selectNodes("//a:multistatus/a:response")
' Select what we are after

For Each aNode In objNodeList

If aNode.hasChildNodes Then

For Each aSecondNode In aNode.childNodes ' 2

Debug.Print "Second: " & aSecondNode.nodeName;

'Debug.Print "Third: " & aThirdNode.nodeName;

If aSecondNode.nodeName = "a:href" Then

sHREF = aSecondNode.Text ' RESET.

sAttachmentFileName = "" ' RESET.

sCN = "" ' RESET

End If

If aSecondNode.hasChildNodes Then

For Each aThirdNode In aSecondNode.childNodes ' 3

If aThirdNode.hasChildNodes Then

For Each aFourthNode In aThirdNode.childNodes '
4

If aFourthNode.hasChildNodes Then

For Each aFifthNode In
aFourthNode.childNodes

Debug.Print aFourthNode.nodeName

Select Case aFourthNode.nodeName

Case "e:attachmentfilename"

sAttachmentFileName =
aFifthNode.Text

Case "i:cn"

sCN = aFifthNode.Text

End Select

Next ' 5

End If

Next ' 4

End If

Next ' 3

End If

If sHREF <> "" And sAttachmentFileName <> "" And sCN <> ""
Then

Set anInstance = New CAttatchmentList

anInstance.href = sHREF

anInstance.attachmentfilename = sAttachmentFileName

anInstance.cn = sCN

MyClasses.Add anInstance, CStr(lListCount)

lListCount = lListCount + 1

sHREF = aSecondNode.Text ' RESET.

sAttachmentFileName = "" ' RESET.

sCN = "" ' RESET

End If

Next '2

End If

Next ' 1

Set ParseAttatchmentListXML = MyClasses

End Function

' TODO: Create a class file called CMailList and paste the code below in.

'Public Class CMailList

Public href As String

Public attachmentfilename As String

Public cn As String

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #3
Hi, Kevin:

Thanks a lot!
I will try it.

Li

"Kevin Yu [MSFT]" wrote:
Hi Li,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to know how to download
attachments using WebDAV. If there is any misunderstanding, please feel
free to let me know.

We can use X-MS-ENUMATTS to go through the attachment list. Use a GET to
extract the stream, which can be save to file.

Here I found a sample:

' VB Example on enumerating and reading attatchments

' TODO: Add a reference to MS XML 4.0.

' TODO: Add a command button (cmdGetAttachmentsList) to a form.

' TODO: Add a multiline text box (txtResponse) with scroll bars to the
form.

' TODO: Change code as per TODO under the command button.

' TODO: Do the TODO sections at the bottom of this document which involve
creating a class.

'

' Also please review the following article, which shows some differences
to note for .NET:

' Managing Microsoft Exchange 2000 Calendars with XML Web Services

'
http://msdn.microsoft.com/library/de...us/dnmes2k/htm
l/calwp_0001.asp

'

Private Sub cmdGetAttachmentsList_Click()

Dim sUserName As String ' Domain/Username for server

Dim sPassword As String ' User's password

Dim sBaseURL As String

Dim sMessage As String

Dim sAttatch As String

Dim sXML As String

Dim aList As Collection

Dim anInst As CAttatchmentList

Dim sOutput As String

txtResponse.Text = ""

' TODO: Change the next four lines to match your user, password and
email

sUserName = "myuser" ' User

sPassword = "mypassword" ' Password

sBaseURL =
"http://myserver.mycompany.com/exchange/Administrator/Inbox/" ' Location of
email.

sMessage = "Test%20Attatch.EML" ' HREF of email I'm going to read

sXML = GetAttachmentsListXML(sBaseURL & sMessage, sUserName, sPassword)

sOutput = "-------------------------------------------------" & vbCrLf
& _

"The XML response:" & vbCrLf & vbCrLf & sXML & vbCrLf &
vbCrLf

Set aList = ParseAttatchmentListXML(sXML)

For Each anInst In aList

sOutput = sOutput &
"-------------------------------------------------" & vbCrLf

sOutput = sOutput & "******* Attatchment: " & anInst.href & vbCrLf

sOutput = sOutput & " attachmentfilename: " &
anInst.attachmentfilename & vbCrLf

sOutput = sOutput & " cn: " & anInst.cn & vbCrLf

sOutput = sOutput & " Attatchment Text: " & vbCrLf

sOutput = sOutput & ReadAnAttatchment(anInst.href, sUserName,
sPassword)

sOutput = sOutput & vbCrLf

Next

Set aList = Nothing

txtResponse.Text = sOutput

End Sub

'---------------------------------------------------------------------------

' GetAttachmentsListXML

' Searches an HREF to an email to find attatchments for the email

' Input

' sHREF - Http reference to the email

' sUserName - Domain/Username for server

' sPassword - Password for the account above

' Returns: An XML document resulting from the search

'---------------------------------------------------------------------------

Function GetAttachmentsListXML(ByVal sHREF As String, ByVal sUserName As
String, ByVal sPassword As String) As String

Const FOLDERITEM = "Inbox/Test1.eml"

Dim HttpWebRequest As Msxml2.XMLHTTP30

Dim strPropReq As String

Dim strOutPutFile As String

Set HttpWebRequest = New Msxml2.XMLHTTP30

With HttpWebRequest

.Open "X-MS-ENUMATTS", sHREF, False, sUserName, sPassword

.setRequestHeader "Content-type:", "text/xml"

.setRequestHeader "Depth", "1,noroot"

.Send

GetAttachmentsListXML = HttpWebRequest.ResponseText

End With

Set HttpWebRequest = Nothing

End Function

'---------------------------------------------------------------------------

' ReadAnAttatchment

' Reads the contents of an attatchment for an email.

' Input

' sHREF - Http reference to the email

' sUserName - Domain/Username for server

' sPassword - Password for the account above

' Returns: The contents of the email attatchment

'---------------------------------------------------------------------------

Private Function ReadAnAttatchment(ByVal sHREF As String, ByVal sUserName
As String, ByVal sPassword As String) As Variant

Dim HttpWebRequest As Msxml2.XMLHTTP30

Dim vReturn As Variant

Set HttpWebRequest = New Msxml2.XMLHTTP30

HttpWebRequest.Open "GET", sHREF, False, sUserName, sPassword

HttpWebRequest.Send

ReadAnAttatchment = HttpWebRequest.ResponseText ' Returns as text

'ReadAnAttatchment = HttpWebRequest.responseBody ' Returns as encoded

Set HttpWebRequest = Nothing

End Function

'---------------------------------------------------------------------------

' ParseAttatchmentListXML

' This will parse the XML document containing the list Attatchment names

' Input:

' sXML - An XML document string containing a list of email attatchments

' Returns:

' A collection of Email attatchemnt references (collection of
CAttatchmentList classes)

'---------------------------------------------------------------------------

Private Function ParseAttatchmentListXML(ByVal sXML As String) As Collection

Dim doc As Msxml2.DOMDocument

Set doc = New Msxml2.DOMDocument

Dim aNode As IXMLDOMNode

Dim aSecondNode As IXMLDOMNode

Dim aThirdNode As IXMLDOMNode

Dim aFourthNode As IXMLDOMNode

Dim aFifthNode As IXMLDOMNode

Dim sHREF As String

Dim sAttachmentFileName As String

Dim sCN As String

Dim lListCount As Long

lListCount = 1

sHREF = ""

sAttachmentFileName = ""

sCN = ""

Dim xmlRoot As IXMLDOMElement

Dim xmlNode As IXMLDOMNode

Dim xmlReq As Msxml2.XMLHTTP40

Dim objNodeList As IXMLDOMNodeList

Dim anInstance As New CAttatchmentList

Dim MyClasses As New Collection ' Create a Collection object.

doc.loadXML (sXML)

Set xmlRoot = doc.documentElement '.documentElemen

Set objNodeList = xmlRoot.selectNodes("//a:multistatus/a:response")
' Select what we are after

For Each aNode In objNodeList

If aNode.hasChildNodes Then

For Each aSecondNode In aNode.childNodes ' 2

Debug.Print "Second: " & aSecondNode.nodeName;

'Debug.Print "Third: " & aThirdNode.nodeName;

If aSecondNode.nodeName = "a:href" Then

sHREF = aSecondNode.Text ' RESET.

sAttachmentFileName = "" ' RESET.

sCN = "" ' RESET

End If

If aSecondNode.hasChildNodes Then

For Each aThirdNode In aSecondNode.childNodes ' 3

If aThirdNode.hasChildNodes Then

For Each aFourthNode In aThirdNode.childNodes '
4

If aFourthNode.hasChildNodes Then

For Each aFifthNode In
aFourthNode.childNodes

Debug.Print aFourthNode.nodeName

Select Case aFourthNode.nodeName

Case "e:attachmentfilename"

sAttachmentFileName =
aFifthNode.Text

Case "i:cn"

sCN = aFifthNode.Text

End Select

Next ' 5

End If

Next ' 4

End If

Next ' 3

End If

If sHREF <> "" And sAttachmentFileName <> "" And sCN <> ""
Then

Set anInstance = New CAttatchmentList

anInstance.href = sHREF

anInstance.attachmentfilename = sAttachmentFileName

anInstance.cn = sCN

MyClasses.Add anInstance, CStr(lListCount)

lListCount = lListCount + 1

sHREF = aSecondNode.Text ' RESET.

sAttachmentFileName = "" ' RESET.

sCN = "" ' RESET

End If

Next '2

End If

Next ' 1

Set ParseAttatchmentListXML = MyClasses

End Function

' TODO: Create a class file called CMailList and paste the code below in.

'Public Class CMailList

Public href As String

Public attachmentfilename As String

Public cn As String

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #4
You're welcome, Li. If you have any questions, please feel free to post
them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
403
by: Independentsoft | last post by:
Hello, Independentsoft is pleased to announce the Release Candidate 2 of WebDAV .NET v1.0, the leading WebDAV protocol API component for Microsoft .NET Framework and Microsoft .NET Compact...
0
1458
by: Andrew Pasetti | last post by:
Hello, There is a document on msdn that describes how to send an email using webdav and vb.net...
0
866
by: Curt Cullens | last post by:
I am trying to use WebDav to display a list of attachments that are in a particular inbox. I can successfully list the attachments, setup the <img src=""> to them, but I am then asked for the...
4
1415
by: Li Weng | last post by:
Hi, I have two questions: 1) If there are more than one attachments, can I still use urn:schema:httpmail:attachmentfilename to get the file names? How? Or I need to use X-MS-ENUMATTS method? ...
6
17077
by: ErwinF | last post by:
Hi there, I would like to know the following: How to send send email attachments using WebDAV in VB .NET? Sample code please................... Thanks for your help.
2
6004
by: Joe George | last post by:
Hi there, How to save email attachments, from exchange, using WebDAV in C#.NET? Sample code please................... Thanks for your help. -- Joe George
7
3460
by: Wiebe Tijsma | last post by:
Hi, I'm using C# + webDAV to create a draft message to be sent in a user's Drafts folder. I can create the message successfully, however when I open the message in outlook, it doesn't show...
0
1199
by: barca933 | last post by:
hello I'm using WebDAV in PHP to get messages from Exchange Server I get all the mailboxes then I get the messages' headers in a specified folder(mailbox) I also could get the attachments and...
2
1348
by: planetthoughtful | last post by:
Hi All, I need to build a console app that can connect to a mailbox on a Microsoft Exchange 2000 Server located on our intranet to do the following: - go through all emails in the inbox -...
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7002
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7203
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5462
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4908
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4588
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3081
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
290
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.