VirtualFile.Open Method ()

 

When overridden in a derived class, returns a read-only stream to the virtual resource.

Namespace:   System.Web.Hosting
Assembly:  System.Web (in System.Web.dll)

abstract Open : unit -> Stream

Return Value

Type: System.IO.Stream

A read-only stream to the virtual file.

The Open method returns a stream containing the data treated as a file by the VirtualPathProvider class. The stream is read-only and is seekable (the CanSeek property is true).

Notes to Inheritors:

In derived classes the Open method must return a seekable stream. If the method returns a stream that does not support seeking, a NotSupportedException is thrown when the stream is passed to the HttpResponse object to write out the data. The exception occurs because the response tries to read the Length property, and on a stream that is not seekable, attempting to access the property causes an exception. For more information, see the CanSeek property.

The following code example is an implementation of the Open method that combines virtual-file-specific information with a template file and then returns the combination. The template file is cached to reduce the overhead of reading the file system multiple times to retrieve the template file. For the full code required to run the example, see the Example section of the VirtualFile class overview.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0
Return to top
Show: