Skip to Main Content
C# in a Nutshell
book

C# in a Nutshell

by Ben Albahari, Ted Neward, Peter Drayton
March 2002
Intermediate to advanced content levelIntermediate to advanced
864 pages
31h 8m
English
O'Reilly Media, Inc.
Content preview from C# in a Nutshell

Name

FileWebRequest

Synopsis

This subclass of WebRequest provides access to resources that use the file URL scheme (such as a file on your local filesystem). Use WebRequest.Create() with a file:// URL to create an instance of this class. The WebRequest.Create() method returns an instance of this class as a reference of type WebRequest.

You may feel a small sense of confusion regarding this type and the “file:” protocol scheme; if a program needs access to a file on the filesystem, why not simply open a System.IO.FileStream instead of using WebRequest.Create("file:/...")? In terms of straight functionality, the System.IO.FileStream call more closely represents the fact that this resource is coming from disk; however, due to the ubiquity of HTTP servers growing within the enterprise, there are often times when a system wishes to equally represent HTTP URLs and filesystem paths within an arbitrary context. For example, a configuration file might be used to indicate where to retrieve user preferences; by specifying the location as an URL rather than an absolute file location, storage of user preferences is permitted on a centralized server without any additional code. (This allows a kind of “roaming preferences” capability within the system.) Many of the .NET tools also use this approach to identify “files” to act upon via command-line parameters.

public class FileWebRequest : WebRequest {
// Protected Constructors
   protected method FileWebRequest( System.Runtime.Serialization.SerializationInfo ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# 8.0 in a Nutshell

C# 8.0 in a Nutshell

Joseph Albahari, Eric Johannsen
C# 10 in a Nutshell

C# 10 in a Nutshell

Joseph Albahari
C# in a Nutshell, Second Edition

C# in a Nutshell, Second Edition

Peter Drayton, Ben Albahari, Ted Neward
Code like a Pro in C#

Code like a Pro in C#

Jort Rodenburg

Publisher Resources

ISBN: 0596001819Catalog PageErrata