1

I need to add items to a SharePoint list using client object model. The issue I am facing is: Suppose I am at a page whose URL is http'://sharepointserver:7575/details.aspx

I want to fetch this complete URL & Similarly I need to fetch the current page name also using client object model. Can someone please guide me Which properties I can use to achieve this as I don't have any idea about client object model coding?

Any help would be greatly appreciated..

Bhargav
  • 124
  • 6
  • 19
  • Why do you need to get absolute path using client object model? You can use simple javascript to achieve that - window.location.href . – Yevgeniy.Chernobrivets Apr 29 '14 at 15:09
  • Also what do you mean by "current page name"? – Yevgeniy.Chernobrivets Apr 29 '14 at 15:10
  • Thank you Yevgeniy for the quick response..!! I will try using javascript as you have mentioned but the requirement is to use client object model only. so, please kindly suggest the procedure to achieve the same by CSOM if possible. As per the second doubt, If I navigate to any page in the SharePoint site, I need to fetch the current page name which I am currently watching. If I navigate to second page, I should be able to fetch the secondpage name. Thank you... – Bhargav Apr 29 '14 at 15:20
  • Well client object model for browser is based on javascript so i think you can use javascript :). As for the second question - i meant what property did you mean? Where do you see it? – Yevgeniy.Chernobrivets Apr 29 '14 at 15:25
  • Hi Yevgeniy..! Suppose I have a sharepoint site http://testing:7575/ I then created two pages firstpage.aspx & secondpage.aspx in this site. Now, I navigated to http://testing:7575/firstpage.aspx So, on page load I need to fetch this name: firstpage.aspx and then if I navigate to http://testing:7575/secondpage.aspx I should fetch this name:secondpage.aspx from the url. Thank you for your continuous support :) – Bhargav May 01 '14 at 04:27
  • Try this location.pathname.substring(location.pathname.lastIndexOf("/") + 1); – Yevgeniy.Chernobrivets May 01 '14 at 09:04
  • I am getting :location does not exist in the current context error – Bhargav May 01 '14 at 09:52
  • Try window.location.pathname.substring(window.location.pathname.lastIndexOf("/") + 1); – Yevgeniy.Chernobrivets May 01 '14 at 10:00
  • Thank you so much Yevgeniy..it's working like magic. Thank you so much :) – Bhargav May 01 '14 at 10:13

1 Answers1

2

Try to use window.location.href to get full request url and window.location.pathname.substring(window.location.pathname.lastIndexOf("/") + 1); to get page name.

Yevgeniy.Chernobrivets
  • 3,194
  • 2
  • 12
  • 14