Setting and Retrieving Custom Properties

Topic Last Modified: 2006-06-11

The following example demonstrates how to set and retrieve properties on items in the Exchange store.

Example

VBScript

Example

Dim InfoNT
Set InfoNT = CreateObject("WinNTSystemInfo")

SetProps "http://" & InfoNT.ComputerName & "/public/test_folder/test1.txt"
GetProps "http://" & InfoNT.ComputerName & "/public/test_folder/test1.txt"

Sub SetProps(sUrl)

    Dim Rec
    Set Rec = CreateObject("ADODB.Record")
    Dim Conn
    Set Conn = CreateObject("ADODB.Connection")
    Conn.Provider = "ExOLEDB.DataSource"
    Conn.Open sUrl
    Rec.Open sUrl, Conn, adModeReadWrite

    Dim Flds
    Set Flds = Rec.Fields
    With Flds
      .Item("urn:schemas-domain-tld:modified") = Now
      .Item("urn:schemas-domain-tld:status") = "Behind Schedule"
      .Item("urn:schemas-domain-tld:author") = "Paul West"
      .Item("urn:schemas-domain-tld:author-email") = """Paul west"" <pw@somewhere.example.com>"
      .Item("urn:schemas-domain-tld:editor") = "Wendy Wheeler"
      .Item("urn:schemas-domain-tld:editor-email") = """Wendy Wheeler"" <ww@somewhere.example.com>"
      .Update
    End With

   ' Clean up.
    Conn.Close
    Rec.Close

    Set Conn = Nothing
    Set Rec = Nothing

End Sub

Sub GetProps(sUrl)

   ' This example shows how to retrieve custom property values
   ' set in the previous snippet.

    Dim Rec
    Set Rec = CreateObject("ADODB.Record")
    Dim Conn
    Set Conn = CreateObject("ADODB.Connection")
    Conn.Provider = "ExOLEDB.DataSource"
    Conn.Open sUrl
    Rec.Open sUrl, Conn, adModeReadWrite


    Dim Flds
    Set Flds = Rec.Fields
    Dim Props(10)
    Props(1) = "urn:schemas-domain-tld:modified"
    Props(2) = "urn:schemas-domain-tld:status"
    Props(3) = "urn:schemas-domain-tld:author"
    Props(4) = "urn:schemas-domain-tld:author-email"
    Props(5) = "urn:schemas-domain-tld:editor"
    Props(6) = "urn:schemas-domain-tld:editor-email"
    For I = 1 To 6
      WScript.Echo Props(I) & vbCrLf
      WScript.Echo Flds(Props(I))

    ' Clean up.
    Conn.Close
    Rec.Close

    Set Conn = Nothing
    Set Rec = Nothing

End Sub
</script>
</job>

Visual Basic

Sub SetProps(sUrl)

    Dim Rec As New Record
    Dim Conn As New Connection
    Conn.Provider = "ExOLEDB.DataSource"
    Conn.Open sUrl
    Rec.Open sUrl, Conn, adModeReadWrite

    Dim Flds As Fields
    Set Flds = Rec.Fields
  With Flds
    .Item("urn:schemas-domain-tld:modified") = Now
    .Item("urn:schemas-domain-tld:status") = "Behind Schedule"
    .Item("urn:schemas-domain-tld:author") = "Paul West"
    .Item("urn:schemas-domain-tld:author-email") = """Paul west"" <pw@somewhere.example.com>"
    .Item("urn:schemas-domain-tld:editor") = "Wendy Wheeler"
    .Item("urn:schemas-domain-tld:editor-email") = """Wendy Wheeler"" <ww@somewhere.example.com>"
    .Update
  End With


  ' Clean up.
  Conn.Close
  Rec.Close

  Set Conn = Nothing
  Set Rec = Nothing

End Sub

Sub GetProps(sUrl)

   ' This example shows how to retrieve custom property values
   ' set in the previous snippet.

    Dim Rec As New Record
    Dim Conn As New Connection
    Conn.Provider = "ExOLEDB.DataSource"
    Conn.Open sUrl
    Rec.Open sUrl, Conn, adModeReadWrite

    Dim Flds As Fields
    Set Flds = Rec.Fields
    Dim Props(10) As Variant
    Props(1) = "urn:schemas-domain-tld:modified"
    Props(2) = "urn:schemas-domain-tld:status"
    Props(3) = "urn:schemas-domain-tld:author"
    Props(4) = "urn:schemas-domain-tld:author-email"
    Props(5) = "urn:schemas-domain-tld:editor"
    Props(6) = "urn:schemas-domain-tld:editor-email"
    For I = 1 To 6
      Debug.Print Props(I) & vbCrLf
      Debug.Print Flds(Props(I))
    Next I

    ' Clean up.
    Conn.Close
    Rec.Close

    Set Conn = Nothing
    Set Rec = Nothing

End Sub