Compartilhar via


Describing Forms of URL Strings

Applies to: SharePoint Foundation 2010

Microsoft SharePoint Foundation uses various forms of URL strings, depending on the context and members that are being used.

SharePoint Foundation 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, https://Server/[sites/]Web_Site/Lists/List_Title/AllItems.aspx.

  • Server-relative URL that is based on the server address and 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 address of a Web site object (SPWeb), that does not begin with a forward slash, and that specifies a complete path from the Web site's address to the 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 URL to an image file that is located in the %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\LAYOUTS\1033\IMAGES 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 might prevent the image from being displayed, depending, for example, on how the full URL is constructed from the location where it is used. The URL is much more likely to fail if you use more than /_layouts at the beginning of the URL.

Url Tokens

SharePoint Foundation supports the following tokens with which to start a relative URL:

  • ~site   Web site (SPWeb) relative link.

  • ~sitecollection   site collection (SPSite) relative link.

In addition, you can use the following tokens within a URL:

  • {ItemId}   Integer ID that represents the item within a list.

  • {ItemUrl}   URL of the item being acted upon. Works only for documents in libraries.

  • {ListId}   GUID that represents the list.

  • {SiteUrl}   URL of the Web site (SPWeb).

  • {RecurrenceId}   Recurrence index. This token is not supported for use in the context menus of list items.

See Also

Concepts

Advanced Extranet Support

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

SharePoint Development Tasks - How Do I...?

Working with List Objects and Collections

Other Resources

Basic Object Model Tasks in SharePoint 2010