Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Let's say that I have created:

  • A SharePoint site collection at http://mysharepoint/.
  • A subsite of that site collection titled Team site at http://mysharepoint/teamsite/.
  • A list titled My List at http://mysharepoint/teamsite/Lists/mylist/.
  • A list view titled My View at 'http://mysharepoint/teamsite/Lists/mylist/Forms/myview.aspx'

In the Managed Client Object model code, let's say that I managed to reference:

  • The subsite as Web teamsite;
  • The list as List mylist;
  • The list view as View myview;

Is there a way to get the corresponding URLs from those three objects? Thanks.

share|improve this question
1  
i assume you already tried teamsite.Url etc? –  int32 Nov 17 '11 at 11:33
    
Also teamsite will be an SPWeb object, not SPSite. –  James Love Nov 17 '11 at 11:42
    
@AndreasScharf teamsite.Url property does not exist in Managed Client Object model. I haven't been able to find the property/method that would serve my purpose. –  Boris Nov 17 '11 at 11:51
    
@JamesLove Thanks for pointing out the mistake. I've updated my question. –  Boris Nov 17 '11 at 11:52
    
I assume you are refering to the script client object model. Please leave a comment if you needed guidance for the "Microsoft.SharePoint.Client" one ^_^ –  SPArchaeologist Nov 17 '11 at 13:34
add comment

3 Answers

up vote 5 down vote accepted

You should be able to use the available property to build the url you require. Just be aware that many of the property must be accessed with a *get_method* sintax.

For the SP.Site use the get_url() "property". For the SP.Web use the get_serverRelativeUrl() property and build up the full url.

For the list... don't know if there is an easier way, but you can resort to the get_serverRelativeUrl() property of the root folder (SP.List.get_rootFolder();). Then build the full url from there.

EDIT: As a reference for those that are using the "Microsoft.SharePoint.Client" namespace. On the Site object you can use the .Url property. Since the Web object does not provide an Url property use the ServerRelativeUrl one and build the full url as needed. Also, you must still compensate for the List object not providing any url property. As above, you can resort using the ServerRelativeUrl of the RootFolder of the list.

share|improve this answer
    
Actually, I was looking for the Microsoft.SharePoint.Client model, but the method names are virtually the same and you resolved my question. Thanks. –  Boris Nov 18 '11 at 8:41
    
ops, sorry. I had read SPSite as SP.Site, so I automatically switched to javascript thinking mode ^_^''. I will update the answer when I get some time on hand. –  SPArchaeologist Nov 18 '11 at 9:06
    
no worries. Thanks for the help. –  Boris Nov 18 '11 at 9:08
add comment

This is how SP.Web absolute url can be constructed:

var clientContext = new SP.ClientContext.get_current();
var site = clientContext.get_site();
var web = clientContext.get_web();
clientContext.load(site,'ServerRelativeUrl', 'Url');
clientContext.load(web, 'ServerRelativeUrl');
clientContext.executeQueryAsync(Function.createDelegate(this, function (sender, args) {
    var fullWebUrl = site.get_url().replace(site.get_serverRelativeUrl(), 
web.get_serverRelativeUrl());
alert(fullWebUrl);
}), Function.createDelegate(this, function (sender, args) {  }));
share|improve this answer
    
This helped me, but it only works when site.get_serverRelativeUrl() is longer than "/". A more flexible solution is: if (site.get_serverRelativeUrl() == "/") return site.get_url() + web.get_serverRelativeUrl(); else return site.get_url().replace(site.get_serverRelativeUrl(), web.get_serverRelativeUrl()); –  Tor Hovland Apr 20 '12 at 8:27
add comment

To get list Properties like URL, ID , Title . Please see below link.

http://yeshagrawal.blogspot.in/2013/09/sharepoint-2013-get-sp-list-title-id.html

share|improve this answer
    
While this may theoretically answer the question, we prefer inclusion of the essential parts of the answer here, and to provide the link for reference. See answer for general guidelines. –  SPDoctor Sep 5 '13 at 9:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.