Partager via


Sorting the Inbox Based on Received Time Using ADO

Topic Last Modified: 2009-07-27

Example

VBScript

Note

The following example uses a file URL with Exchange OLE DB (ExOLEDB) provider. The ExOLEDB provider also supports The HTTP: URL Scheme. Using The HTTP: URL Scheme allows both client and server applications to use a single URL scheme.

'Sorting the Inbox based on received time using ADO

<!--
Build Instructions:
Save this file in a newly created virtual dir under wwwroot
-->
<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<%
Dim Rec
Dim Rs
Dim strURL
Dim strQ
Dim strSubj
Dim DomainName
Dim strLocalPath

Set Rec = CreateObject("ADODB.Record")
Set Rs = CreateObject("ADODB.Recordset")

' set your own values to these variables:
DomainName = "somedomain.microsoft.com"
strLocalPath = "MBX/User1/inbox"

strURL = "file://./backofficestorage/" & DomainName & "/" & strLocalPath
Rec.Open strURL

' build the query string
strQ = "select "
strQ = strQ & " ""urn:schemas:mailheader:date"""
strQ = strQ & ", ""urn:schemas:mailheader:sender"""
strQ = strQ & ", ""urn:schemas:mailheader:subject"""
strQ = strQ & ", ""urn:schemas:mailheader:received"""
strQ = strQ & ", ""DAV:contentclass"""
strQ = strQ & ", ""DAV:href"""
strQ = strQ & " from scope ('shallow traversal of "
strQ = strQ & Chr(34) & strURL & Chr(34) & "') "

' sort received time in descending order(can also use ascending)
strQ = strQ & " ORDER BY ""urn:schemas:mailheader:received"" DESC"

Rs.Open strQ, Rec.ActiveConnection

Rs.MoveFirst

' display all of the sorted messages
Do Until Rs.EOF
Response.Write "<b>Subject:</b><br>"
Response.Write Rs.Fields("urn:schemas:mailheader:subject").Value & "<br>"
Response.Write "<b>Date Sent:</b><br>"
Response.Write Rs.Fields("urn:schemas:mailheader:date").Value & "<br>"
Response.Write "<b>Date Received:</b><br>"
Response.Write Rs.Fields("urn:schemas:mailheader:date").Value & "<br>"
Response.Write "<b>Content-Class:</b><br>"
Response.Write Rs.Fields("DAV:contentclass").Value & "<br>"
Response.Write "<b>URL:</b><br>"
Response.Write Rs.Fields("DAV:href").Value & "<br>"
Response.Write "</p>"
Rs.MoveNext
Loop

Rs.Close
Rec.Close
%>
<P> </P>

</BODY>
</HTML>