I have created a custom webpart and deployed it in sharepoint. Now i want to modify the webpart and use the url of the site page where the web part is embedded. How can i access the url progmatically?
1
votes
2 Answers
1
votes
If you mean in the Webpart codebehind you can reference it like this:
string currentWebUrl = SPContext.Current.Web.Url;
NOTE: SPContext.Current.Site\Web (unlike new SPWeb\SPSite) does NOT need to be disposed.
Hope this helps.
Resource:
- SPContext MSDN (http://msdn.microsoft.com/en-us/library/ms475883.aspx)