1

I've added a feature to my onet.xml file which gets activated whenever a site gets created. However, that feature needs to know the url of the site being created. I thought I could figure that out from the current SPContext within the activation event of the feature, but when I created the site I got a null reference on SPContext.Current.

Is that to be expected, or have I done something wrong? If that is the case, does anyone have any suggestions how I can dynamically learn the URL of the site being created?

Thanks

user247417
  • 11
  • 2
  • Just to clarify, when I refer to a site, I'm only actually referring to SPWeb objects, not the SPSite site collection which has already been created up front. – user247417 Jan 10 '10 at 10:49

1 Answers1

5

It seems like you have created a feature receiver? They don't use SPContext but find the site they have been activated on through the properties, like so:

    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        using (SPWeb web = properties.Feature.Parent as SPWeb)
        {...}
    }
ArjanP
  • 2,172
  • 2
  • 15
  • 22