Thursday, November 10, 2011

Programmatically get site URL

I guess that connection to the SharePoint list is one of the most needed requirement. How to connect to the SharePoint list I already described here, but one of the important thing when connection to the SharePoint list is needed is site URL. Site URL can be typed directly to the source code, but I wouldn't recommend this approach. Reason is simple - Application, workflow, event receiver, etc. are usually deployed first at developing server and then on the test server and finally on the production server (this is one of the developing method). Whenever application is moved to another server the rebuilding is needed because of direct URL typing. Wouldn't be better if any other changes wouldn't be required when location of solution is changed? I guess yes :)
And this is the way how to do it in a case of SPSite:
SPSite site = new SPSite(this.workflowProperties.Site.Url + this.workflowProperties.Web.ServerRelativeUrl);

Please don't hesitate to comment any other location independent approaches ;)

No comments:

Post a Comment