다음을 통해 공유


Forms of URL Strings

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

Windows SharePoint Services uses different forms of URL strings, depending on the context and members that are being used. Certain members require an absolute URL, such as the SPSite constructor, or methods in the Microsoft.SharePoint.Administration namespace that require a uniform resource identifier (URI) for a parameter. Most members in the object model instead require a relative URL that is based on the address of the server, such as the Add methods of the SPSiteCollection class. However, some members in the object model require or accept a relative URL that is based on the current Web site, such as the Add methods of the SPWebCollection class or the OpenWeb method of the SPSite class.

Windows SharePoint Services parses URL strings to determine the form of URL based on a specified protocol (for example, http:) or on the placement of a forward slash (/) within the string. Depending on the particular member, you can use the following URL forms:

  • Absolute URL that specifies a full path and that begins by specifying a protocol. For example, http://Server/[sites/]Web_Site/Lists/List_Title/AllItems.aspx.

  • Server-relative URL that is based on the server address that begins with a forward slash, specifying a complete path from top-level Web site to file name. For example, /[sites/]Web_Site/Lists/List_Title/AllItems.aspx.

  • Web site-relative URL that is based on the Web site address that does not begin with a forward slash and that specifies a complete path from folder name to file name. For example, Lists/List_Title/AllItems.aspx.

  • URL relative to a file or folder that is based on the folder containing the file that does not contain any forward slashes and that specifies the name of the file. For example, AllItems.aspx.

Note

There is no concept of a "site collection-relative URL" and passing such a URL may cause the code to fail.

When you create a hard-coded URL to a file you place within the LAYOUTS directory, specify a path that uses the root Web site of the site collection, but that does not include a subsite within the path. For example, use /_layouts/images/MyImage.gif for an image file, not /MySubsite/_layouts/images/MyImage.gif. Specifying a subsite in the path prevents the image from being displayed.

See Also

Concepts

Getting References to Sites, Web Applications, and other Key Objects

How Do I... in Windows SharePoint Services

Working with List Objects and Collections

Other Resources

Sample Object Model Tasks