Hot answers tagged

10

From your code it would seem that you are trying to set a web-application property from a site collection scoped feature. If you are using SharePoint 2010, I can assume that you are experiencing the effect of the new "RemoteAdministratorAccessDenied" security setting, which among the others by default block any attempt to alter a web app property from a ...


8

Yep the place to do it is the feature activated portion of the feature receiver. You can check if one of your others are already activated and throw an exception if they are. Certain exceptions when thrown will display the message to the end user, others will just say an unexpected event occurred. I think if you throw an applicationexception it will ...


7

As EStruyf said, you can change the deployment configuration and debug the code for your Feature Event Receivers. But, you can also attach the event receivers after making sure List is created, so put this code after your list is created. public class Feature1EventReceiver : SPFeatureReceiver { public override void ...


7

Your plan is good, and respects good practices (at least the practices I've been following for ages). Your approach is to: Create the solution in VS Create one feature (scope: Web) Create two classes for the event receivers (both inheriting from SPItemEventReceiver) Add a feature event receiver on the feature (inheriting from SPFeatureReceiver) In the ...


5

There an easier way to do this using the SharePoint API: SPWeb web = SPContext.Current.Web; PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web); publishingWeb.CustomMasterUrl = "/_catalogs/masterpage/mycustom.master"; publishingWeb.CustomMasterUrl.SetInherit(true, true); publishingWeb.Update();


5

Don't do it, you will break your farm. Also, you'll leave it completely unsupported and the next service pack or cumulative update will probably just replace it. What is it you need to do? There'll be a better, supported method for what you want to do without renaming out-of-the-box system files. Edit your question and provide some more information, I'll be ...


4

Assuming the feature is at site collection level and your "Site Pages" library is in root web: public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { SPSite sitecollection = properties.Feature.Parent as SPSite; SPWeb web = site.RootWeb; SPList list = web.Lists["Site Pages"]; ...


4

Short answer: you can't. And why would you create the database using a feature? If you are creating an installer anyway, create the DB there using a db create script or a custom seetup action. As for storing the DB connectionstring and or DB credentials: Use the SecureStore Service Application. See this article for information on how to configure the ...


4

The code compiles and runs fine for me as long as there is a reference to Microsoft.SharePoint (2010). Are you building a console application? In that case make sure you are using the .NET 3.5 framework (not compact or anything else) and set the platform target to Any CPU in the build section of the project properties. BTW. note that you are leaking a site ...


3

Try running a check on the parent web to see if the feature is activated. Since this is only applying to sub webs and it is in the FeatureActivated event, it will already be activated on the parent for you to verify. Edit Code added to check if web.ParentWeb != null bool isChild = false; if (web.ParentWeb != null) { foreach (SPFeature parentFeature ...


3

You need to use the Update() method on the SPListItem object. Also, you want the line: listitem["Activated Time"] = DateTime.Now.TimeOfDay; to be simply: listitem["Activated Time"] = DateTime.Now; otherwise you'll get an unhandled exception. This is the code I have, which works (the method being the same one you've selected): SPSite site = ...


3

I would recommend to use the first method - Create the Form in SPD, save it in .aspx and include it in a List definition feature. Benefits Creating the form in SPD and doing the modifications required are pretty much easy. For eg.- Adding a list view web part or modifying an XSLT would be quiet easier in SPD. Now, adding .aspx in a list definition in VS ...


3

Please follow this tutorial, I have done it thousands of time and it always work the same way. http://msdn.microsoft.com/en-us/library/ff798479.aspx


3

Found the answer: The problem really was that the exception was being thrown within the delegate. Hence the FeatureActivated just ran smoothly and the feature seemed activated. Fortunately SPLongOperation can be instantiated with a Page: new SPLongOperation(Page page) - problem is that in a Feature Receiver i don't have this.Page. I found the beautiful ...


3

My solution to the problem was to change assembly version from 1.0.0.0 to 1.0.0.1 and build the SharePoint project. After that I deleted feature receiver and added feature receiver again so that feature manifest XML file gets updated with correct version of feature receiver assembly. More details on ...


2

You should use Delete() method of SPWeb.Lists SPWeb webSite = properties.Feature.Parent as SPWeb; SPList myCustomList = mySite.Lists["MyCustomList"]; mySite.Lists.Delete(myCustomList.ID); mySite.Update(); You should also create a new SPSite object while running a code as elevated privileges: SPSecurity.RunWithElevatedPrivileges(delegate() ...


2

If I remember correctly the flow is: Site Collection Scoped Features Web Scoped Features Lists Modules Your stapled features would be shot in after Site collection scoped features or Web scoped features (depending on scope) and hence the lists is not guaranteed to be created before the lists. Found a source here: ...


2

I would suggest that you break the whole thing into two features, first one to deploy the List Template and second one to create the instance of the list based on template.. On the later one, you will need to define Feature Activation Dependency of List Template feature.. Both features can be hidden and you just need to activate the Feature that creates ...


2

Make sure to not use SPContext.Current in the FeatureReciever, this will be NULL in powershell (due to lack of HttpContext basically). This is one of the most common cause of errors in FeatureReceivers


2

Looks like your master page is being used by device channels throughout your sites. Microsoft doesn't provide a public API for viewing or modifying the configured master pages for a device channel. With that said, in my book (SharePoint 2013 WCM Advanced Cookbook: http://tinyurl.com/lutktay), I have some samples on how to view and modify the configured ...


2

I found the problem: my solution was in Sandboxed mode! Changed the "Sandboxed solution" project's property to False and now it compiles :)


2

as far as I know retracting solutions doesn't deactivate their features, so although you wont be able to find or activate/deactivate those features, their references are still there. on the particular case of event receivers, it could turn out to be a major problem. the receiver may still be attached and if you redeploy/reactivate you may end up with firing ...


2

The visual web part should be included to the Site-scoped feature, as a result properties.Feature.Parent is a SPSite object. You need to check feature scope and use the code below if the scope is site. SPSite site = properties.Feature.Parent as SPSite; if (site != null){ SPWeb web = site.RootWeb; SPList laptopList = web.Lists["Laptops"]; ... }


2

The problem you would have is timing, the field must have been created before you provision your content type. So the FeatureActivated is a no go. I would not go for FeatureInstalling either since you can not control with ease the execution order. I sometimes uses the FeatureActivated event, but in those cases I create both content type, fields, and binds ...


2

Looks like it is a DLL caching issue. When you start Powershell command line window, it loads all DLLs available in the GAC. So, if you have updated DLL for the feature receiver, and deploying it within the same PS session then it will not reload updated DLL. I had experienced similar behaviour before. To tackle it, I created two seperate PS1 files. First ...


2

Well. It really depends on which feature you have to activate. The id of a feature does not change during its life. This means that if you can find out the id you will be sure it stays the same, regardless of the specific SharePoint farm instance. That said, you can "hardcode" your ID in a support class, much like SharePoint does with fields id in the ...


2

The SharePoint Timer Windows Service (SPTimerV4) may be holding a copy of your DLL in memory and you need to flush it by restarting that Windows service.


2

I would try not calling site.RootWeb repeatedly like that. Sometimes in the SharePoint API calling a property like that (e.g. SPList.DefaultView ) actually returns a different object each time. Thus, your call to update is on a different object to the one you updated. I do wonder if that is happening here. Instead, use a variable and pass that around: ...


2

If you are providing "custom.aspx" through your custom solution/feature the most logical place for doing backup of that file is by using SPFeatureReceiver.FeatureDeactivating method. So when you deactivate your feature backup is created and when you again activate it the new file will be provisioned. If you are using modules or if you are providing ...


2

Also the dlls are deployed in GAC , so make sure change the settings. Follow this article http://www.sharepointnutsandbolts.com/2007/03/how-to-debug-sharepoint-feature.html



Only top voted, non community-wiki answers of a minimum length are eligible