VirtualFile::Open Method
When overridden in a derived class, returns a read-only stream to the virtual resource.
Assembly: System.Web (in System.Web.dll)
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 InheritorsIn 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.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.