Csujo
Csujo

Reputation: 507

SharePoint url - what kind of element or what part is the site url?

I have an url what points a SharePoint element. I do not know the type of the element it can be a list, a document library, an element in these or just a site url. I can only use the Web Services of SharePoint. I have to decide the type of it.

I found a solution: the GetUrlSegments WS can give this information but it can work if I call the WS at the subsite where the element is in. A know just the url I don not know what part of the url is the site url.

How can I decide of the type of the element from an url?

Or how can I decide url of the site (or subsite) from an url?

Upvotes: 2

Views: 159

Answers (1)

Csujo
Csujo

Reputation: 507

I have found the answer. It is not so simple but usable.

  1. Call the sitedata.asmx.GetSiteAndWeb WS in the main site with the input url. It returns the main site url (strSite) and the subsite url (strWeb) from the given url.
  2. Call the sitedata.asmx.GetURLSegments WS in the subsite what you got at the first point with the input url.
  3. If the GetURLSegments returns nothing: The url points to a site.

    If the GetURLSegments returns only listId: The url points to a list. With the lists.asmx.GetList you can get information from the list.

    If the GetURLSegments returns with listId and itemId: The url points to a list item. With the lists.asmx.GetListItems you can get information from the item.

Upvotes: 1

Related Questions