none
SPWeb with full URL? RRS feed

  • Question

  • Based on several posts and other entries on the Forum, I am running into issues.

    I am tasked with writing a SharePoint 2010 timer job that will loop through a list of absolute URLs to various objects within the site and see which, if any, have been removed.

    So I start with the full URL to the object (mostly ASPX and PDFs) and expect to be able to get the site and web to get to the list object via the absolute URL, however this is failing.

    chckFavURL = "https://hostheader.com/subsite1/subsite2/subsite3/library/My Page.aspx";
                using (SPSite favSite = new SPSite(chckFavURL))
                {
                    using (SPWeb favWeb = favSite.OpenWeb(chckFavURL))
                    {
                        SPListItem favorite = favWeb.GetListItem(chckFavURL);
                    }
                }

    The favSite is not the subsite3 as expected, rather is the root site. I've tried OpenWeb and not passing in the absolute URL with the same results, and of course, because favSite is the root site, the SPListItem is failing because the ASPX is not on the roote site.

    Can anyone advise where I'm misstepping?


    - Thank you. Respectfully, Janette M. Ricker

    Thursday, February 20, 2014 8:21 PM

Answers

  • Working this morning I thought perhaps it was the space in the URL that might have been causing the issue, so I added

    chckFavURL = Uri.EscapeUriString("https://hostheader.com/subsite1/subsite2/subsite3/library/My Page.aspx");

    I also removed the URL being passed into the SPWeb:

    using (SPWeb favWeb = favSite.OpenWeb())

    and it now appears I'm getting the correct Site/Web and of course the list item itself.

    Thank you.


    - Thank you. Respectfully, Janette M. Ricker

    • Marked as answer by JaeEmAre Friday, February 21, 2014 1:17 PM
    Friday, February 21, 2014 1:17 PM

All replies

  • check the below post I believe it's the same question 

    http://social.msdn.microsoft.com/Forums/en-US/7e2f44ef-6d2b-49c6-a29a-bb5be15a5347/how-get-spweb-object-from-web-exact-url


    Hope that helps|Amr Fouad|MCTS,MCPD sharePoint 2010

    Thursday, February 20, 2014 11:00 PM
  • Thank you Amr, I thought that was the same question too, however it is not exactly, they appear to be passing in only to the subsite, not to the library and actual list item. I've tried all of the answers (and there are several marked as answer) in that post and with no help, I still get the top level site as the SPSite.

    - Thank you. Respectfully, Janette M. Ricker

    Friday, February 21, 2014 12:52 PM
  • Working this morning I thought perhaps it was the space in the URL that might have been causing the issue, so I added

    chckFavURL = Uri.EscapeUriString("https://hostheader.com/subsite1/subsite2/subsite3/library/My Page.aspx");

    I also removed the URL being passed into the SPWeb:

    using (SPWeb favWeb = favSite.OpenWeb())

    and it now appears I'm getting the correct Site/Web and of course the list item itself.

    Thank you.


    - Thank you. Respectfully, Janette M. Ricker

    • Marked as answer by JaeEmAre Friday, February 21, 2014 1:17 PM
    Friday, February 21, 2014 1:17 PM