Returing Virtual Directory Path From Web Application

If you consume a SPWebApplication object as a parameter, you can return the virtual directory path by using the GetIisSettingsWithFallback() method to return the settings for a specified SharePoint zone.

Here is a static method that demonstrates how to do it:


public static string GetVirtualDirectoryPath(SPWebApplication webApp)
string path = string.Empty;
if (webApp != null)
path = webApp.GetIisSettingsWithFallback(SPUrlZone.Default).Path.ToString();
catch (Exception exception)

return path;



One thought on “Returing Virtual Directory Path From Web Application”

  1. Thanks alot!

    I have been looking for this for a few days. This has shortened my code totally.

    Is there a way to obtain the Virtual Directory Path of an extended SharePoint web application ?

    Thanks alot again,

Leave a Reply

Your email address will not be published. Required fields are marked *