0

I am trying to access a different site collection through an Event receiver. Event receiver does what i want but it does in the same site collection. i have following code

 using (SPSite destsite = new SPSite("http://man:8787/ONE/"))
  {
    string currentURL = destsite.Url.ToString()  

   } 

i always get currentURL = http://man:8787

i never get currentURL = http://man:8787/ONE

I have a working site collection at http://man:8787/ONE

is there anything changed in 2013, am i doing anything wrong.

Servy
  • 202,030
  • 26
  • 332
  • 449
user388969
  • 337
  • 1
  • 9
  • 30
  • Are you sure that `http://man:8787/ONE/` is a separate site collection and not a separate site in the same site collection? – Servy Mar 19 '15 at 20:23
  • boom yeah they are sub sites in same site collections i never realized that...i am being stupid here.....i hate myself so much now....thanks – user388969 Mar 19 '15 at 20:29

1 Answers1

0

From what you are describing we can assume one or two things:

http://man:8787 is a SiteCollection - call it with SPSite

If current url from the SPSite("http://man:8787/ONE/") always is http://man:8787 then http://man:8787/ONE/ is a website inside that sitecollection, hence you should use SPWeb.

If you want that website at that specific location, use the following code:

using (SPSite site = new SPSite("http://man:8787/ONE/"))
{
    using (SPWeb web = site.OpenWeb())
    { 
       //magic happens here
    }
}

Edit: There is an awesome answer over at SharePoint.SE, which lifts some of the confusion around SPSite, SPWeb etc: https://sharepoint.stackexchange.com/questions/23241/getting-my-head-round-spsite-vs-spweb-vs-anything-else

Community
  • 1
  • 1
Marco
  • 22,856
  • 9
  • 75
  • 124