473,405 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 6406
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
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
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
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
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
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
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
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
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
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...

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.