Export (0) Print
Expand All

FileWebResponse.ContentType Property

Gets the content type of the file system resource.

Namespace:  System.Net
Assembly:  System (in System.dll)

'Declaration
Public Overrides ReadOnly Property ContentType As String

Property Value

Type: System.String
The value "binary/octet-stream".

The ContentType property contains the content type of the file system resource. The value of ContentType is always "binary/octet-stream".

The following example uses the ContentType property to obtain the content type of the file system resource.

Public Shared Sub GetPage(url As [String])

    Try 
        Dim fileUrl As New Uri("file://" + url)
        ' Create a 'FileWebrequest' object with the specified Uri  
        Dim myFileWebRequest As FileWebRequest = CType(WebRequest.Create(fileUrl), FileWebRequest)
        ' Send the 'fileWebRequest' and wait for response.     
        Dim myFileWebResponse As FileWebResponse = CType(myFileWebRequest.GetResponse(), FileWebResponse)

        ' The ContentLength and ContentType received as headers in the response object are also exposed as properties. 
        ' These provide information about the length and type of the entity body in the response.
        Console.WriteLine(ControlChars.Cr + "Content length :{0}, Content Type : {1}", myFileWebResponse.ContentLength, myFileWebResponse.ContentType)
        myFileWebResponse.Close()
    Catch e As WebException
        Console.WriteLine(ControlChars.Lf + ControlChars.Cr + "The Reason for failure is : {0}", e.Status)
    Catch e As Exception
        Console.WriteLine(ControlChars.Cr + "The following exception was raised : {0}", e.Message)
    End Try

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft