In The Hand LtdIn The Hand
FileWebRequest Class
NamespacesInTheHand.NetFileWebRequest
.NET Components for Mobility
Provides a file system implementation of the WebRequest class.
Declaration Syntax
C#Visual Basic
public class FileWebRequest : WebRequest
Public Class FileWebRequest _
	Inherits WebRequest
Members
All MembersMethodsProperties



IconMemberDescription
Abort()()()()
Aborts the Request
(Inherited from WebRequest.)
AuthenticationLevel
Gets or sets values indicating the level of authentication and impersonation used for this request.
(Inherited from WebRequest.)
BeginGetRequestStream(AsyncCallback, Object) HostProtectionAttribute.
When overridden in a descendant class, provides an asynchronous version of the GetRequestStream()()()() method.
(Inherited from WebRequest.)
BeginGetResponse(AsyncCallback, Object) HostProtectionAttribute.
When overridden in a descendant class, begins an asynchronous request for an Internet resource.
(Inherited from WebRequest.)
CachePolicy
Gets or sets the cache policy for this request.
(Inherited from WebRequest.)
ConnectionGroupName
When overridden in a descendant class, gets or sets the name of the connection group for the request.
(Inherited from WebRequest.)
ContentLength
Gets or sets the content length of the data being sent.
(Overrides WebRequest.ContentLength.)
ContentType
Gets or sets the content type of the data being sent. This property is reserved for future use.
(Overrides WebRequest.ContentType.)
CreateObjRef(Type)
Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
(Inherited from MarshalByRefObject.)
Credentials
Gets or sets the credentials that are associated with this request. This property is reserved for future use.
(Overrides WebRequest.Credentials.)
EndGetRequestStream(IAsyncResult)
When overridden in a descendant class, returns a Stream for writing data to the Internet resource.
(Inherited from WebRequest.)
EndGetResponse(IAsyncResult)
When overridden in a descendant class, returns a WebResponse.
(Inherited from WebRequest.)
Equals(Object)
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Finalize()()()()
Allows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection.
(Inherited from Object.)
GetHashCode()()()()
Serves as a hash function for a particular type.
(Inherited from Object.)
GetLifetimeService()()()()
Retrieves the current lifetime service object that controls the lifetime policy for this instance.
(Inherited from MarshalByRefObject.)
GetObjectData(SerializationInfo, StreamingContext)
Populates a SerializationInfo with the data needed to serialize the target object.
(Inherited from WebRequest.)
GetRequestStream()()()()
Returns a Stream object for writing data to the file system resource.
(Overrides WebRequest.GetRequestStream()()()().)
GetResponse()()()()
Returns a response to a file system request.
(Overrides WebRequest.GetResponse()()()().)
GetType()()()()
Gets the Type of the current instance.
(Inherited from Object.)
Headers
Gets a collection of the name/value pairs that are associated with the request. This property is reserved for future use.
(Overrides WebRequest.Headers.)
ImpersonationLevel
Gets or sets the impersonation level for the current request.
(Inherited from WebRequest.)
InitializeLifetimeService()()()()
Obtains a lifetime service object to control the lifetime policy for this instance.
(Inherited from MarshalByRefObject.)
MemberwiseClone(Boolean)
Creates a shallow copy of the current MarshalByRefObject object.
(Inherited from MarshalByRefObject.)
MemberwiseClone()()()()
Creates a shallow copy of the current Object.
(Inherited from Object.)
Method
Gets or sets the protocol method used for the request. This property is reserved for future use.
(Overrides WebRequest.Method.)
PreAuthenticate
Gets or sets a value that indicates whether to preauthenticate a request. This property is reserved for future use.
(Overrides WebRequest.PreAuthenticate.)
Proxy
Gets or sets the network proxy to use for this request. This property is reserved for future use.
(Overrides WebRequest.Proxy.)
RegisterPrefix()()()()
Register this class with the WebRequest class.

RequestUri
Gets the URI requested by this instance.
(Overrides WebRequest.RequestUri.)
Timeout
Gets or sets the length of time, in milliseconds, before the request times out.
(Inherited from WebRequest.)
ToString()()()()
Returns a String that represents the current Object.
(Inherited from Object.)
UseDefaultCredentials
When overridden in a descendant class, gets or sets a Boolean value that controls whether DefaultCredentials are sent with requests.
(Inherited from WebRequest.)
Remarks
The FileWebRequest class implements the WebRequest abstract base class for Uniform Resource Identifiers (URIs) that use the file:// scheme to request local files.

You must call the static method RegisterPrefix()()()() before this class can be used with Create(String). You only need to call RegisterPrefix()()()() once in your application.

To obtain an instance of FileWebRequest, use the Create(String) method after calling RegisterPrefix()()()(). You can also use the WebClient class to upload and download files.

Examples
The following code example uses the FileWebRequest class to access a file system resource.
CopyVB.NET
'
' This example creates or opens a text file and stores a string in it. 
' Both the file and the string are passed by the user.
' Note. For this program to work, the folder containing the test file
' must be shared, with its permissions set to allow write access. 


Imports System.Net
Imports System
Imports System.Diagnostics
Imports System.IO
Imports System.Text
Imports InTheHand.Net

Namespace Mssc.PluggableProtocols.File

    Module TestGetRequestStream

        Class TestGetRequestStream

            Private Shared myFileWebRequest As FileWebRequest

            ' Show how to use this program.
            Private Shared Sub showUsage()
                Console.WriteLine(ControlChars.Lf + "Please enter file name and timeout :")
                Console.WriteLine("Usage: vb_getrequeststream <systemname>/<sharedfoldername>/<filename> timeout")
                Console.WriteLine("Example: vb_getrequeststream ngetrequestrtream() ndpue/temp/hello.txt  1000")
                Console.WriteLine("Small time-out values (for example, 3 or less) cause a time-out exception.")
            End Sub

            Private Shared Sub makeFileRequest(ByVal fileName As String, ByVal timeout As Integer)
                Try
                    ' Create a Uri object.to access the file requested by the user. 
                    Dim myUrl As New Uri("file://" + fileName)

                    ' Create a FileWebRequest object.for the requeste file.
                    myFileWebRequest = CType(WebRequest.CreateDefault(myUrl), FileWebRequest)

                    ' Set the time-out to the value selected by the user.
                    myFileWebRequest.Timeout = timeout

                    ' Set the Method property to POST  
                    myFileWebRequest.Method = "POST"

                Catch e As WebException
                    Console.WriteLine(("WebException is: " + e.Message))
                Catch e As UriFormatException
                    Console.WriteLine(("UriFormatWebException is: " + e.Message))
                End Try

            End Sub

            Private Shared Sub writeToFile()
                Try
                    ' Enter the string to write to the file.
                    Console.WriteLine("Enter the string you want to write:")
                    Dim userInput As String = Console.ReadLine()

                    ' Convert the string to a byte array.
                    Dim encoder As New ASCIIEncoding
                    Dim byteArray As Byte() = encoder.GetBytes(userInput)

                    ' Set the ContentLength property.
                    myFileWebRequest.ContentLength = byteArray.Length

                    Dim contentLength As String = myFileWebRequest.ContentLength.ToString()

                    Console.WriteLine(ControlChars.Lf + "The content length is {0}.", contentLength)


                    ' Get the file stream handler to write to the file.
                    Dim readStream As Stream = myFileWebRequest.GetRequestStream()

                    ' Write to the stream. 
                    ' Note. For this to work the file must be accessible
                    ' on the network. This can be accomplished by setting the property
                    ' sharing of the folder containg the file.  
                    ' FileWebRequest.Credentials property cannot be used for this purpose.
                    readStream.Write(byteArray, 0, userInput.Length)


                    Console.WriteLine(ControlChars.Lf + "The String you entered was successfully written to the file.")

                    readStream.Close()

                Catch e As WebException
                    Console.WriteLine(("WebException is: " + e.Message))
                Catch e As UriFormatException
                    Console.WriteLine(("UriFormatWebException is: " + e.Message))
                End Try

            End Sub

            Public Shared Sub Main(ByVal args() As String)

                If args.Length < 2 Then
                    showUsage()
                Else
                    makeFileRequest(args(0), Integer.Parse(args(1)))
                    writeToFile()
                End If

            End Sub 'Main


        End Class 'TestGetRequestStream


    End Module

End Namespace
Inheritance Hierarchy

Assembly: InTheHand.Net (Module: InTheHand.Net) Version: 7.0.0.0