FileWebRequest Class
Provides a file system implementation of the WebRequest class.
Assembly: System (in System.dll)
| Name | Description | |
|---|---|---|
![]() | FileWebRequest(SerializationInfo, StreamingContext) | Obsolete. Initializes a new instance of the FileWebRequest class from the specified instances of the SerializationInfo and StreamingContext classes. |
| Name | Description | |
|---|---|---|
![]() | AuthenticationLevel | Gets or sets values indicating the level of authentication and impersonation used for this request.(Inherited from WebRequest.) |
![]() | CachePolicy | Gets or sets the cache policy for this request.(Inherited from WebRequest.) |
![]() | ConnectionGroupName | Gets or sets the name of the connection group for the request. This property is reserved for future use.(Overrides WebRequest.ConnectionGroupName.) |
![]() | 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.) |
![]() | CreatorInstance | Obsolete. When overridden in a descendant class, gets the factory object derived from the IWebRequestCreate class used to create the WebRequest instantiated for making the request to the specified URI.(Inherited from WebRequest.) |
![]() | Credentials | Gets or sets the credentials that are associated with this request. This property is reserved for future use.(Overrides WebRequest.Credentials.) |
![]() | 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.) |
![]() | 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.) |
![]() | RequestUri | Gets the Uniform Resource Identifier (URI) of the request.(Overrides WebRequest.RequestUri.) |
![]() | Timeout | Gets or sets the length of time until the request times out.(Overrides WebRequest.Timeout.) |
![]() | UseDefaultCredentials | This API supports the product infrastructure and is not intended to be used directly from your code. Always throws a NotSupportedException.(Overrides WebRequest.UseDefaultCredentials.) |
| Name | Description | |
|---|---|---|
![]() | Abort() | Cancels a request to an Internet resource.(Overrides WebRequest.Abort().) |
![]() | BeginGetRequestStream(AsyncCallback, Object) | Begins an asynchronous request for a Stream object to use to write data.(Overrides WebRequest.BeginGetRequestStream(AsyncCallback, Object).) |
![]() | BeginGetResponse(AsyncCallback, Object) | Begins an asynchronous request for a file system resource.(Overrides WebRequest.BeginGetResponse(AsyncCallback, Object).) |
![]() | 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.) |
![]() | EndGetRequestStream(IAsyncResult) | Ends an asynchronous request for a Stream instance that the application uses to write data.(Overrides WebRequest.EndGetRequestStream(IAsyncResult).) |
![]() | EndGetResponse(IAsyncResult) | Ends an asynchronous request for a file system resource.(Overrides WebRequest.EndGetResponse(IAsyncResult).) |
![]() | Equals(Object) | Determines whether the specified object is equal to the current object.(Inherited from Object.) |
![]() | Finalize() | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.) |
![]() | GetHashCode() | Serves as the default hash function. (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.(Overrides WebRequest.GetObjectData(SerializationInfo, StreamingContext).) |
![]() | GetRequestStream() | Returns a Stream object for writing data to the file system resource.(Overrides WebRequest.GetRequestStream().) |
![]() | GetRequestStreamAsync() | When overridden in a descendant class, returns a Stream for writing data to the Internet resource as an asynchronous operation.(Inherited from WebRequest.) |
![]() | GetResponse() | Returns a response to a file system request.(Overrides WebRequest.GetResponse().) |
![]() | GetResponseAsync() | When overridden in a descendant class, returns a response to an Internet request as an asynchronous operation.(Inherited from WebRequest.) |
![]() | GetType() | |
![]() | InitializeLifetimeService() | Obtains a lifetime service object to control the lifetime policy for this instance.(Inherited from MarshalByRefObject.) |
![]() | MemberwiseClone() | |
![]() | MemberwiseClone(Boolean) | Creates a shallow copy of the current MarshalByRefObject object.(Inherited from MarshalByRefObject.) |
![]() | ToString() | Returns a string that represents the current object.(Inherited from Object.) |
| Name | Description | |
|---|---|---|
![]() ![]() | ISerializable.GetObjectData(SerializationInfo, StreamingContext) | This API supports the product infrastructure and is not intended to be used directly from your code. Populates a SerializationInfo object with the required data to serialize the FileWebRequest. |
The FileWebRequest class implements the WebRequestabstract base class for Uniform Resource Identifiers (URIs) that use the file:// scheme to request local files.
Do not use the FileWebRequest constructor. Use the WebRequest.Create method to initialize new instances of the FileWebRequest class. If the URI scheme is file://, the Create method returns a FileWebRequest object.
The GetResponse method makes a synchronous request for the file specified in the RequestUri property and returns a FileWebResponse object that contains the response. You can make an asynchronous request for the file using the BeginGetResponse and EndGetResponse methods.
When you want to write data to a file, the GetRequestStream method returns a Stream instance to write to. The BeginGetRequestStream and EndGetRequestStream methods provide asynchronous access to the write data stream.
The FileWebRequest class relies on the File class for error handling and code access security.
The following code example uses the FileWebRequest class to access a file system resource.
' ' 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.IO Imports System.Text 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
Available since 1.1
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.




