tailieunhanh - ASP.NET 4 Unleased - p 117

1134 CHAPTER 24 Advanced Navigation Typically, you override the FileExists() and GetFile() methods to retrieve a file from your data store. If you want to represent directories, you also need to override the DirectoryExists() and GetDirectory() methods. Several of these methods are related to caching. The VirtualPathProvider needs to know when a file has been modified so that it can retrieve the new version of the file and compile it. By default, the Framework uses a file dependency to determine when a file has been modified on the hard drive. However, in this situation a SqlCacheDependency is used because the files will. | 1134 CHAPTER 24 Advanced Navigation Typically you override the FileExists and GetFile methods to retrieve a file from your data store. If you want to represent directories you also need to override the DirectoryExists and GetDirectory methods. Several of these methods are related to caching. The VirtualPathProvider needs to know when a file has been modified so that it can retrieve the new version of the file and compile it. By default the Framework uses a file dependency to determine when a file has been modified on the hard drive. However in this situation a SqlCacheDependency is used because the files will be stored in a database. The VirtualPathProvider also includes a useful property Previous Returns the previously registered VirtualPathProvider. The Previous property enables you to use the default VirtualPathProvider. For example if you want to store some files in the file system and other files in the database you can use the Previous property to avoid rewriting all the logic for working with files in the file system. The GetFile method returns an instance of the VirtualFile class. When using the VirtualPathProvider you must create a new class that inherits from the VirtualFile class. This class contains the following properties IsDirectory Always returns False. Name Returns the name of the file. VirtualPath Returns the virtual path of the file. The VirtualFile class also contains the following method Open Returns the contents of the file. Typically when creating a class that inherits from the VirtualFile class you override the Open method. For example we override this method to get the contents of a file from a database table in the code sample built in this section. The GetDirectory method returns an instance of the VirtualDirectory class. This class contains the following properties Children Returns all the files and directories that are children of the current directory. Directories Returns all the directories that are children of the current .