4

Can someone help me understand why I am unable to get the "Url" property from this example? I get the error "Field or Property 'Url' does not exist":

        ClientContext ctx = new ClientContext("http://<weburl>");
        WebCollection allWebs = ctx.Web.Webs;

        var webCollection = ctx.LoadQuery(
            allWebs.Include(
                web => web.Title,
                web => web.ServerRelativeUrl,
                web => web.Url            
            )
        );

        ctx.ExecuteQuery();
        foreach (Web w in webCollection)
        {
            //w.ServerRelativeUrl returns a value, but
            //w.Url gives me an error. why?
        }

2 Answers 2

5

This error occurs since you are using SharePoint Server 2013 Client Components SDK (ver. 15) or SharePoint Online Client Components SDK (ver. 16) but against SharePoint 2010.

Microsoft.SharePoint.Client.Web Url Property was introduced in CSOM ver. 15

How to determine Web Url in SharePoint 2010

The following example demonstrates how to get sub webs url in SharePoint 2010:

var webs = ctx.LoadQuery(
            ctx.Web.Webs.Include(
                web => web.Title,
                web => web.ServerRelativeUrl
            )
        );
ctx.Load(ctx.Site, s => s.Url);
ctx.ExecuteQuery();

foreach (Web web in webs)
{
    var webUrl = ctx.Site.Url + web.ServerRelativeUrl;
}
1

URL is not a property of Microsoft.SharePoint.Client.Web however, ServerRelativeUrl is.

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.web_properties(v=office.14).aspx

What are you trying to accomplish?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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