0

Suppose I have an app and install it to "https://me.sharepoint.com/" (My Office 365 developer site). In my app, user can type a web url and get all lists under this web. And here is my code:

var webUrl = 'https://me.sharepoint.com/';
var context = SP.ClientContext.get_current();
var appContextSite = new SP.AppContextSite(context, webUrl);
var web = appContextSite.get_web();
var lists = web.get_lists();

context.load(lists);
context.executeQueryAsync(function (sender, args) {
    // Do something
}, function (sender, args) {
    // Error handling
});

I set app permission to "Web/Read", so it can only access "https://me.sharepoint.com/". During testing, I set webUrl to "https://me.sharepoint.com/sub1" (sub1 exists), and I get Access denied error, which is the correct behaviour. But if I set webUrl to "https://me.sharepoint.com/sub2" (sub2 doesn't exist), it loads "https://me.sharepoint.com/" and doesn't throw an exception. How can I catch this exception to tell the user it doesn't exist? Thanks in advance!

I tried to load web and compare web.get_url() with webUrl to see if they are equal (To make it simple, we assume webUrl is a full url). But it doesn't work if user types the url like "https://me.sharepoint.com/_layouts/15/start.aspx#/SitePages/DevHome.aspx" or even "https://me.sharepoint.com/Shared%20Documents/Page1.aspx?PageView=Shared&InitialTabId=Ribbon.WebPartPage&VisibilityContext=WSSWebPartPage". We can still get web from those urls, but web.get_url() only returns "https://me.sharepoint.com". So under this condition, the logic even doesn't work for existed web.

0

I think you have the answer right in your question:

It seems SharePoint start wit the full URL you submit and tries to find a site, if it does not it trims from the last "/" and tries again

It continues like this until a site is found or all "/" are gone from the URL

  • Thanks. Then how can I check if a web exist? – Xiaodan Mao May 29 '14 at 2:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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