Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How to retrieve an object's security descriptor property by using Visual Basic .NET


View products that this article applies to.

Summary

This article describes how to use the HttpWebRequest class and the HttpWebResponse class from the "System.Net" namespace to retrieve an object's http://schemas.microsoft.com/exchange/security/descriptor property by using Microsoft Visual Basic .NET on a computer that is running Microsoft Exchange 2000 Server.

↑ Back to the top


More information

To retrieve an object's security descriptor property, follow these steps:
  1. Start Microsoft Visual Studio .NET.
  2. On the File menu, point to New, and then click Project.
  3. In the Visual Basic Projects types list, click Console Application.

    By default, the Module1.vb file is created.
  4. In the code window, replace the code with the following:
    Imports System.Net
    Imports System.IO
    
    Module Module1
        Sub Main()
            ' TODO: Replace with your object URL.
            Dim sUri As String = "http://ExchServer/Public/MyFolder/Test.EML"
    
            Dim myUri As System.Uri = New System.Uri(sUri)
            Dim HttpWRequest As HttpWebRequest = WebRequest.Create(myUri)
    
            Dim strSDType As String = "descriptor"
            Dim sQuery As String
            sQuery = "<?xml version='1.0' encoding='utf-8'?>" & _
             "<propfind xmlns=""DAV:"">" & _
             "<prop xmlns:r=""http://schemas.microsoft.com/exchange/security/"">" & _
             "<isfolder/>" & _
             "   <r:" & strSDType & "/>" & _
             "</prop>" & _
             "</propfind>"
    
            ' TODO: Replace with the appropriate user credential.
            Dim myCred As NetworkCredential = New NetworkCredential("Domain\UserName", "Password")
            Dim MyCredentialCache As CredentialCache = New CredentialCache()
            MyCredentialCache.Add(myUri, "Basic", myCred)
            HttpWRequest.Credentials = MyCredentialCache
    
            ' Set headers.
            HttpWRequest.KeepAlive = False
            HttpWRequest.Headers.Set("Pragma", "no-cache")
            HttpWRequest.ContentType = "text/xml"
            HttpWRequest.Headers.Set("Translate", "f")
            HttpWRequest.Headers.Set("Depth", "0")
            HttpWRequest.ContentLength = sQuery.Length
    
            'Set the request timeout to 5 minutes.
            HttpWRequest.Timeout = 300000
            ' set the request method
            HttpWRequest.Method = "PROPFIND"
    
            ' Store the data in a byte array.
            Dim ByteQuery() As Byte = System.Text.Encoding.ASCII.GetBytes(sQuery)
            HttpWRequest.ContentLength = ByteQuery.Length
            Dim QueryStream As Stream = HttpWRequest.GetRequestStream()
            ' write the data to be posted to the Request Stream
            QueryStream.Write(ByteQuery, 0, ByteQuery.Length)
            QueryStream.Close()
    
            ' Send the request and get the response.
            Dim HttpWResponse As HttpWebResponse = HttpWRequest.GetResponse()
    
            ' Get the status and the headers.
            Dim iStatCode As Integer = HttpWResponse.StatusCode
            Dim sStatus As String = iStatCode.ToString()
            Console.WriteLine("Status: {0} {1}", sStatus, HttpWResponse.StatusDescription.ToString())
    
            Console.WriteLine("Request Headers:")
            Console.WriteLine(HttpWRequest.Headers.ToString())
            Console.WriteLine("Response Headers:")
            Console.WriteLine(HttpWResponse.Headers.ToString())
    
            ' Get the response stream.
            Dim strm As Stream = HttpWResponse.GetResponseStream()
    
            ' Read the response stream.
            Dim sr As StreamReader = New StreamReader(strm)
            Dim sText As String = sr.ReadToEnd()
            Console.WriteLine("Response: {0}", sText)
    
            ' Close the stream.
            strm.Close()
    
            ' Clean up
            HttpWRequest = Nothing
            HttpWResponse = Nothing
            MyCredentialCache = Nothing
            myCred = Nothing
            strm = Nothing
            sr = Nothing
        End Sub
    End Module
  5. Search for TODO in the code, and then modify the code for your environment.
  6. Press F5 to build and to run the program.
  7. Make sure that the object's security descriptor property has been received from the response stream.

↑ Back to the top


Keywords: KB314195, kbhowtomaster

↑ Back to the top

Article Info
Article ID : 314195
Revision : 3
Created on : 4/13/2004
Published on : 4/13/2004
Exists online : False
Views : 505