System.Net.FileWebRequest Class

Assembly: System.dll
Namespace: System.Net
Summary
Provides a file system implementation of the WebRequest class.
C# Syntax:
[Serializable]
public class FileWebRequest : WebRequest
Remarks
The FileWebRequest class implements the WebRequestabstract base class for URIs that use the file:// scheme to request local files.

Do not use the FileWebRequest.#ctor constructor. Use the WebRequest.Create method to initialize new instances of the FileWebRequest class. If the URI scheme is file:// , the WebRequest.Create method returns a FileWebRequest instance.

The FileWebRequest.GetResponse method makes a synchronous request for the file specified in the FileWebRequest.RequestUri property and returns a FileWebResponse instance containing the response. You can make an asynchronous request for the file using the FileWebRequest.BeginGetResponse and FileWebRequest.EndGetResponse methods.

When you want to write data to a file, the FileWebRequest.GetRequestStream method returns a Stream instance to write to. The FileWebRequest.BeginGetRequestStream and FileWebRequest.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.

See also:
System.Net Namespace | File

System.Net.FileWebRequest Member List:

Public Properties
ConnectionGroupName Read-write

Overridden:
Gets or sets the name of the connection group for the request. This property is reserved for future use.
ContentLength Read-write

Overridden:
Gets or sets the content length of the data being sent.
ContentType Read-write

Overridden:
Gets or sets the content type of the data being sent. This property is reserved for future use.
Credentials Read-write

Overridden:
Gets or sets the credentials associated with this request. This property is reserved for future use.
Headers Read-only

Overridden:
Gets a collection of the name/value pairs associated with the request. This property is reserved for future use.
Method Read-write

Overridden:
Gets or sets the protocol method used for the request. This property is reserved for future use.
PreAuthenticate Read-write

Overridden:
Gets or sets a value indicating whether to preauthenticate a request. This property is reserved for future use.
Proxy Read-write

Overridden:
Gets or sets the network proxy to use for this request. This property is reserved for future use.
RequestUri Read-only

Overridden:
Gets the URI of the request.
Timeout Read-write

Overridden:
Gets or sets the length of time until the request times out.
Public Methods
Abort
(inherited from System.Net.WebRequest)
See base class member description: System.Net.WebRequest.Abort


Cancels an asynchronous request to an Internet resource.
BeginGetRequestStream Overridden:
Begins an asynchronous request for a Stream instance to use to write data.
BeginGetResponse Overridden:
Begins an asynchronous request for a file system resource.
CreateObjRef
(inherited from System.MarshalByRefObject)
See base class member description: System.MarshalByRefObject.CreateObjRef


Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
EndGetRequestStream Overridden:
Ends an asynchronous request for a Stream instance that the application uses to write data.
EndGetResponse Overridden:
Ends an asynchronous request for a file system resource.
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetLifetimeService
(inherited from System.MarshalByRefObject)
See base class member description: System.MarshalByRefObject.GetLifetimeService


Retrieves the current lifetime service object that controls the lifetime policy for this instance.
GetRequestStream Overridden:
Returns a Stream instance for writing data to the file system resource.
GetResponse Overridden:
Returns a response to a file system request.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
InitializeLifetimeService
(inherited from System.MarshalByRefObject)
See base class member description: System.MarshalByRefObject.InitializeLifetimeService


Obtains a lifetime service object to control the lifetime policy for this instance.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Constructors
ctor #1 Initializes a new instance of the FileWebRequest class from the specified instances of the SerializationInfo and StreamingContext classes.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Net.FileWebRequest Member Details

ctor #1
Summary
Initializes a new instance of the FileWebRequest class from the specified instances of the SerializationInfo and StreamingContext classes.
C# Syntax:
protected FileWebRequest(
   SerializationInfo serializationInfo,
   StreamingContext streamingContext
);
Parameters:

serializationInfo

A SerializationInfo instance that contains the information required to serialize the new FileWebRequest instance.

streamingContext

An instance of the StreamingContext class that contains the source of the serialized stream associated with the new FileWebRequest instance.

Remarks
This constructor implements the ISerializable interface for the FileWebRequest class.
See also:
MSDN: serialization

Return to top


Overridden Property: ConnectionGroupName (read-write)
Summary
Gets or sets the name of the connection group for the request. This property is reserved for future use.
C# Syntax:
public override string ConnectionGroupName {get; set;}
Remarks
The FileWebRequest.ConnectionGroupName property is currently not used by the FileWebRequest class.

Return to top


Overridden Property: ContentLength (read-write)
Summary
Gets or sets the content length of the data being sent.
C# Syntax:
public override long ContentLength {get; set;}
Exceptions
Exception Type Condition
ArgumentException FileWebRequest.ContentLength is less than 0.

Return to top


Overridden Property: ContentType (read-write)
Summary
Gets or sets the content type of the data being sent. This property is reserved for future use.
C# Syntax:
public override string ContentType {get; set;}
Remarks
The FileWebRequest.ContentType property contains the media type of the data being sent. This is typically the MIME encoding of the content. The FileWebRequest.ContentType property is currently not used by the FileWebRequest class.

Return to top


Overridden Property: Credentials (read-write)
Summary
Gets or sets the credentials associated with this request. This property is reserved for future use.
C# Syntax:
public override ICredentials Credentials {get; set;}
Remarks
Because the FileWebRequest class does not authenticate requests for files from the local file system, it ignores the contents, if any, of the FileWebRequest.Credentials property. Authentication for FileWebRequest is handled by the access control lists for the file resource in the underlying file system.

Return to top


Overridden Property: Headers (read-only)
Summary
Gets a collection of the name/value pairs associated with the request. This property is reserved for future use.
C# Syntax:
public override WebHeaderCollection Headers {get;}
Remarks
The FileWebRequest.Headers property is currently not used by the FileWebRequest class.

Return to top


Overridden Property: Method (read-write)
Summary
Gets or sets the protocol method used for the request. This property is reserved for future use.
C# Syntax:
public override string Method {get; set;}
Remarks
The FileWebRequest.Method property is currently not used by the FileWebRequest class.

Return to top


Overridden Property: PreAuthenticate (read-write)
Summary
Gets or sets a value indicating whether to preauthenticate a request. This property is reserved for future use.
C# Syntax:
public override bool PreAuthenticate {get; set;}
Remarks
The FileWebRequest.PreAuthenticate property is currently not used by the FileWebRequest class.

Return to top


Overridden Property: Proxy (read-write)
Summary
Gets or sets the network proxy to use for this request. This property is reserved for future use.
C# Syntax:
public override IWebProxy Proxy {get; set;}
Remarks
The FileWebRequest.Proxy property is currently not used by the FileWebRequest class.

Return to top


Overridden Property: RequestUri (read-only)
Summary
Gets the URI of the request.
C# Syntax:
public override Uri RequestUri {get;}

Return to top


Overridden Property: Timeout (read-write)
Summary
Gets or sets the length of time until the request times out.
C# Syntax:
public override int Timeout {get; set;}
Exceptions
Exception Type Condition
ArgumentException FileWebRequest.Timeout is set to less than 0.

Return to top


Method: Abort()
Inherited
See base class member description: System.Net.WebRequest.Abort

Summary
Cancels an asynchronous request to an Internet resource.
C# Syntax:
public virtual void Abort();
Exceptions
Exception Type Condition
NotSupportedException Any attempt is made to access the method, when the method is not overridden in a descendant class.
Remarks
The WebRequest.Abort method cancels asynchronous requests to Internet resources started with the WebRequest.BeginGetResponse method.

Note The WebRequest class is an abstract class. The actual behavior of WebRequest instances at run time is determined by the descendant class returned by the WebRequest.Create method. For more information about default values and exceptions, see the documentation for the descendant classes, such as HttpWebRequest and FileWebRequest.

Return to top


Overridden Method: BeginGetRequestStream(
   AsyncCallback callback,
   object state
)
Summary
Begins an asynchronous request for a Stream instance to use to write data.
C# Syntax:
public override IAsyncResult BeginGetRequestStream(
   AsyncCallback callback,
   object state
);
Parameters:

callback

The AsyncCallback delegate.

state

An object containing state information for this request.

Return Value:
An IAsyncResult that references the asynchronous request.
Exceptions
Exception Type Condition
ProtocolViolationException The FileWebRequest.Method property is GET and the application writes to the stream.
InvalidOperationException The stream is being used by a previous call to FileWebRequest.BeginGetRequestStream
ApplicationException No write stream is available.
Remarks
The FileWebRequest.BeginGetRequestStream method starts an asynchronous request for a stream used to send data to a file system resource. The callback method that implements the AsyncCallback delegate uses the FileWebRequest.EndGetRequestStream method to return the request stream.
See also:
FileWebRequest.GetRequestStream | FileWebRequest.EndGetRequestStream | MSDN: makingasynchronousrequests

Return to top


Overridden Method: BeginGetResponse(
   AsyncCallback callback,
   object state
)
Summary
Begins an asynchronous request for a file system resource.
C# Syntax:
public override IAsyncResult BeginGetResponse(
   AsyncCallback callback,
   object state
);
Parameters:

callback

The AsyncCallback delegate.

state

An object containing state information for this request.

Return Value:
An IAsyncResult that references the asynchronous request.
Exceptions
Exception Type Condition
InvalidOperationException The stream is already in use by a previous call to FileWebRequest.BeginGetResponse.
Remarks
The FileWebRequest.BeginGetResponse method starts an asynchronous request for a file system resource. The asynchronous callback method that implements the AsyncCallback delegate uses the FileWebRequest.EndGetResponse method to return the actual FileWebResponse.
See also:
FileWebRequest.GetResponse | FileWebRequest.EndGetResponse | MSDN: makingasynchronousrequests

Return to top


Method: CreateObjRef(
   Type requestedType
)
Inherited
See base class member description: System.MarshalByRefObject.CreateObjRef

Summary
Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
C# Syntax:
public virtual ObjRef CreateObjRef(
   Type requestedType
);
Parameters:

requestedType

The Type of the object that the new ObjRef will reference.

Return Value:
Information required to generate a proxy.
Exceptions
Exception Type Condition
RemotingException This instance is not a valid remoting object.

Return to top


Overridden Method: EndGetRequestStream(
   IAsyncResult asyncResult
)
Summary
Ends an asynchronous request for a Stream instance that the application uses to write data.
C# Syntax:
public override Stream EndGetRequestStream(
   IAsyncResult asyncResult
);
Parameters:

asyncResult

An IAsyncResult referencing the pending request for a stream.

Return Value:
A Stream instance that the application uses to write data.
Exceptions
Exception Type Condition
ArgumentNullException asyncResult is null.
Remarks
The FileWebRequest.EndGetRequestStream method completes an asynchronous stream request that was started by the FileWebRequest.BeginGetRequestStream method.

Note To avoid timing issues with garbage collection, be sure to close the response stream by calling the Stream.Close method on the stream returned by FileWebResponse.GetResponseStream after calling FileWebRequest.EndGetResponse.
See also:
FileWebRequest.GetRequestStream | FileWebRequest.BeginGetRequestStream | MSDN: makingasynchronousrequests

Return to top


Overridden Method: EndGetResponse(
   IAsyncResult asyncResult
)
Summary
Ends an asynchronous request for a file system resource.
C# Syntax:
public override WebResponse EndGetResponse(
   IAsyncResult asyncResult
);
Parameters:

asyncResult

An IAsyncResult referencing the pending request for a response.

Return Value:
A WebResponse that contains the response from the file system resource.
Exceptions
Exception Type Condition
ArgumentNullException asyncResult is null.
Remarks
The FileWebRequest.EndGetResponse method completes an asynchronous request for a file system resource that was started with the FileWebRequest.BeginGetResponse method.
See also:
FileWebRequest.GetResponse | FileWebRequest.BeginGetResponse | MSDN: makingasynchronousrequests

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~FileWebRequest();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetLifetimeService()
Inherited
See base class member description: System.MarshalByRefObject.GetLifetimeService

Summary
Retrieves the current lifetime service object that controls the lifetime policy for this instance.
C# Syntax:
public object GetLifetimeService();
Return Value:
An object of type ILease used to control the lifetime policy for this instance.
Remarks
For more information about lifetime services, see the LifetimeServices class.

Return to top


Overridden Method: GetRequestStream()
Summary
Returns a Stream instance for writing data to the file system resource.
C# Syntax:
public override Stream GetRequestStream();
Return Value:
A Stream for writing data to the file system resource.
Exceptions
Exception Type Condition
WebException The request times out.
Remarks
The FileWebRequest.GetRequestStream method returns a Stream instance for writing data to the file system resource.

The FileWebRequest.GetRequestStream method provides synchronous access to the Stream. For asynchronous access, use the FileWebRequest.BeginGetRequestStream and FileWebRequest.EndGetRequestStream methods.

See also:
FileWebRequest.BeginGetRequestStream

Return to top


Overridden Method: GetResponse()
Summary
Returns a response to a file system request.
C# Syntax:
public override WebResponse GetResponse();
Return Value:
A WebResponse that contains the response from the file system resource.
Exceptions
Exception Type Condition
WebException The request timed out.
Remarks
The FileWebRequest.GetResponse method returns a WebResponse instance containing the response from the file system resource.

The FileWebRequest.GetResponse method provides synchronous access to the WebResponse. For asynchronous access, use the FileWebRequest.BeginGetResponse and FileWebRequest.EndGetResponse methods.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: InitializeLifetimeService()
Inherited
See base class member description: System.MarshalByRefObject.InitializeLifetimeService

Summary
Obtains a lifetime service object to control the lifetime policy for this instance.
C# Syntax:
public virtual object InitializeLifetimeService();
Return Value:
An object of type ILease used to control the lifetime policy for this instance. This is the current lifetime service object for this instance if one exists; otherwise, a new lifetime service object initialized to the value of the LifetimeServices.LeaseManagerPollTime property.
Remarks
For more information about lifetime services, see the LifetimeServices class.
Example
The following code example demonstrates creating a lease.
 public class MyClass : MarshalByRefObject
 {
   public override Object InitializeLifetimeService()
   {
     ILease lease = (ILease)base.InitializeLifetimeService();
     if (lease.CurrentState == LeaseState.Initial)
     {
          lease.InitialLeaseTime = TimeSpan.FromMinutes(1);
          lease.SponsorshipTimeout = TimeSpan.FromMinutes(2);
           lease.RenewOnCallTime = TimeSpan.FromSeconds(2);
     }
       return lease;
   }
 }

    

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.