Posted by: Cirilo Meggiolaro | 04/1/2009

Tip of the day #169 – VirtualPathUtility helper class

The static VirtualPathUtility class available under the System.Web namespace provides several methods to help you handle operations with virtual paths on your web applications.

Methods

The following methods are available:

  • string AppendTrailingSlash(string virtualPath): Appends the literal slash mark (/) to the end of the virtual path, if one does not already exist;
  • string Combine(string basePath, string relativePath): Combines a base path and a relative path;
  • string GetDirectory(string virtualPath): Returns the directory portion of a virtual path;
  • string GetExtension(string virtualPath): Retrieves the extension of the file that is referenced in the virtual path;
  • string GetFileName(string virtualPath): Retrieves the file name of the file that is referenced in the virtual path;
  • bool IsAbsolute(string virtualPath): Returns a Boolean value indicating whether the specified virtual path is absolute; that is, it starts with a literal slash mark (/);
  • bool IsAppRelative(string virtualPath): Returns a Boolean value indicating whether the specified virtual path is relative to the application;
  • string MakeRelative(string fromPath, string toPath): Returns the relative virtual path from one virtual path containing the root operator (the tilde [~]) to another;
  • string RemoveTrailingSlash(string virtualPath): Removes a trailing slash mark (/) from a virtual path
  • string ToAbsolute(string virtualPath): Converts a virtual path to an application absolute path;
  • string ToAbsolute(string virtualPath, string applicationPath): Converts a virtual path to an application absolute path using the specified application path;
  • string ToAppRelative(string virtualPath): Converts a virtual path to an application-relative path using the application virtual path that is in the AppDomainAppVirtualPath property;
  • string ToAppRelative(string virtualPath, string applicationPath): Converts a virtual path to an application-relative path using a specified application path.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: