Working Process
In a Visual Studio Web Part, I was trying to create a Sharepoint List using a Feature Receiver Event. Every thing works fine when I deployed the solution using Visual Studio 2010.
Problem
I tried deploying the solution using STSADM Command or Powershell scripts. The deployment went fine but the Sharepoint List was not getting created. After research I found out the issue was in the activation code. I was using SPContext.Current.Web.Url. Now the correct way to do this is mentioned below.
If the Feature Scope="Web"
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSecurity.RunWithElevatedPrivileges(delegate
{
SPWeb _web = (SPWeb)properties.Feature.Parent;
});
}
If the Feature Scope="Site"
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSecurity.RunWithElevatedPrivileges(delegate
{
SPSite _site = (SPSite)properties.Feature.Parent;
});
}
Hope you find this helpfull. Please comment if you have any queries.
No comments:
Post a Comment