Understanding Absolute and Relative URL Addresses
|SharePoint Designer Developer Reference|
Microsoft Office SharePoint Designer uses absolute URL addressing. However, Office SharePoint Designer does provide a way to change the addressing of URLs between absolute and relative by using the MakeAbs and MakeRel methods.
What is an absolute URL?
A URL defines the location of an object. When a URL is absolute, it defines unambiguously where the object is located. For example, http://msdn.microsoft.com/office/default.aspx is the exact location of the welcome page for Microsoft Office Developer Center on MSDN. The object, default.aspx, is stored in the Office folder on the Web server msdn.microsoft.com.
A disk-based Web site that contains your Web sites on your hard drive might have a base absolute URL such as file:///C:/My Documents/My Web Sites, file:///C:/WINNT/Profiles/your logon alias/Personal/My Web Sites/index.htm, or file:///C:/Documents and Settings/your logon alias/My Documents/My Web Sites.
As Web sites are updated and the structure of a Web site evolves, documents can often be moved from one location to another in a Web site. If you use a relative address, you may break some links. For example, if you have a document that has a hyperlink to another Web page, you can use an absolute URL to ensure that the hyperlink always refers to that object. For example, a document such as file:///C:/My Documents/My Webs/mydocument.htm, may contain an absolute URL that refers to the welcome page, http://msdn.microsoft.com/office/default.aspx. If the document, default.htm, is moved to another location, the absolute URL for the document always refers to the page on the Web server at msdn.microsoft.com in the folder named Office. If the URL for the hyperlink to default.aspx is a relative address, the link could be broken if mydocument.htm is moved to a different subsite or main Web site.
What is a relative URL?
Instead of specifying every piece of a URL that fully defines how to find an object, you can abbreviate a URL to make it "relative" to a current location. Relative URLs are typically used when creating a Web site in which the pages in it refer to other pages within the Web site. A page such as file:///C:/My Documents/My Web Sites/mydocument.htm can have a relative URL to "newdocument.htm" or to "../files/default.htm". In these two cases, the referred addresses for these files are file:///C:/My Documents/My Web Sites/newdocument.htm and file:///C:/My Documents/files/default.htm. Notice that the full Web server or explicit directory is not specified; the location is based on where the document is located.
Relative URLs are very useful, particularly when constructing a site in one place and then publishing it to another place. For example, you might not want to specify a server name while authoring a Web page, because the server name will change when the Web site is published.
How can an absolute URL be made relative?
URLs can be made relative either to a server or to a page. To make a URL relative to a folder or to a Web site, you need to make the URL relative either to a server or to a page, because Office SharePoint Designer treats the URL as if it were relative to a page in that folder or Web site. Each relative URL, combined with its base URL, fully specifies where the object is located.
When you have an absolute address such as http://www.microsoft.com/mywebsite with an image file called MyPicture.gif residing in the images folder on the Web site, you can create a relative URL for that address by deciding whether the relative address refers to a server or a page. For a server-relative URL, you use "mywebsite/images/MyPicture.gif" with the server name as the base for the relative URL, which fully defines the location of the object. For a page-relative URL, you use "images/MyPicture,gif" with the server name and the Web site name as the base for the relative URL, which fully defines the location of the object. For a folder-relative URL, you use "MyPicture.gif" with the server name, Web site name, and folder name as the base for the relative URL; this relative address fully defines the location of the object.
A folder-relative URL can also be specified from a different folder, for example, "../images/MyPicture.gif" could be used if the referring document were in another top-level folder on the same Web site and server. The ".." is the notation used to indicate the parent folder of the current URL address.
Programmatic Access to Relative URLs
After you decide whether to use server, Web site, or folder-relative URLs, you can determine which objects to use. For server or Web site-relative URLs, you work with methods related to the Web object. For folder-relative URLs, you be work with methods related to the WebFolder object.
Converting relative and absolute URLs
Recommended use for Office SharePoint Designer is absolute addressing. However, after you specify a relative URL within Office SharePoint Designer, you can use the MakeAbs method to convert it into an absolute URL. Similarly, if you have an absolute URL and you want to insert a reference into a document as a relative URL, you can use the MakeRel method to convert the address to a relative address. You can also use the MakeAbs and MakeRel methods to convert a hyperlink for a Web, WebFolder, WebFile, NavigationNode, or DesignerDocument object.