Sitecore CMS and everything related RSS 2.0
 Thursday, April 16, 2009

UrlString provides a simple wrapper around URLs, both relative and absolute. Many Sitecore UI components receive data from querystring parameters, and UrlString provides convenient  method for constructing URLs with querystring parameters.

Assembling an URL:

UrlString url = new UrlString("/path/to/mypage.aspx");

url["id"] = "{some-id}";
url["db"] = "master";

string result = url.ToString(); // "/path/to/mypage.aspx?id=some-id&db=master"

Tweaking existing url:

UrlString url = new UrlString("/path/to/mypage.aspx?id=some-id&db=master");

url["db"] = "web";
url["mode"] = "new";

string result = url.ToString(); // "/path/to/mypage.aspx?id=some-id&db=web&mode=new"

Some methods in Sitecore API accept UrlString to add more data. ItemUri class can embed itself in a UrlString, so that you can pass information uniquely identifying a Sitecore item in a URL:

UrlString url = new UrlString("page.aspx");

Sitecore.Context.Item.Uri.AddToUrlString(url);

string result = url.ToString(); // "page.aspx?id={id}&la=en&v=1&db=master"

Compared to System.Uri, Sitecore's UrlString is very lax in accepting any kinds of input and giving it back.

Thursday, April 16, 2009 12:30:48 PM (FLE Standard Time, UTC+02:00)  #    Comments [0]
Sitecore | API
Archive
<April 2009>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789
Blogroll
 Alex de Groot
Few words about SiteCore from Holland
 Alexander Shyba
Sitecore Support
 Anders Dreyer
Anders Dreyer on Sitecore Development
 Jakob Christensen
Sitecore Core Development
 Lars Fløe Nielsen
Lars's ramblings about development and business processes
 Ole Thrane
Sitecore API
 Runi Thomsen
Runi Thomsen Sitecore Toughts
 The Sitecore Experience
The Sitecore Experience
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010
Alexey Rusakov
Sign In
Statistics
Total Posts: 211
This Year: 0
This Month: 0
This Week: 0
Comments: 0
Themes
Pick a theme:
All Content © 2010, Alexey Rusakov
DasBlog theme 'Business' created by Christoph De Baene (delarou)