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 FeatureActivated(...


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

You should dispose of the SPWeb reference after each feature receiver has executed. public override void FeatureActivated(SPFeatureReceiverProperties properties) { using (SPWeb web = properties.Feature.Parent as SPWeb) { } } Admittedly, feature receivers such as this are one of the few places where you don't "have to" dispose of your SPWeb ...


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

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

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 = SPContext....


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

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: http://blogs.msdn.com/b/chrischiaro/...


3

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 ...


3

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 ...


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 http://slavensemper.blogspot.hr/2015/08/failed-to-load-...


2

I ran into something similar. The problem is that the InfoPath Form Template is under the element's sub-folder. You need to put the .xsn file in the same folder as Feature.xml. I could not find a way to do this using the SharePoint Project template in Visual Studio 2010. So I used a WSPBuilder project instead.


2

Take a look at this blog. In the section marked SharePoint Exception Handling: If you only catch and log the exception without throwing the SPException then the feature will complete the requested feature activation or de-activation (which ever the user is currently requesting) instead of aborting the feature activation or de-activation.


2

FeatureActivated is an asynchronous event that happens after the feature was activated. I know of no way to change the activation status except deactivating (SPFeature.Remove(id)) the feature programmatically, but not sure thats what you want...


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

I am assuming that the feature is web application scoped. Are you activating the feature through the browser (central admin)? Try activating it from powershell/stsadm instead. I have always found that if i try to modify the web.config, from the process that is using the web.config, things seem to go bad. function New-WebConfigMod { param( [...


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

I have tried this code snippet (from console application): using(SPSite site = new SPSite("http://mycoolsite")) { using(SPWeb web = site.OpenWeb()) { SPList list = web.Lists["My List"]; SPField fldTitle = list.Fields["Title"]; fldTitle.Required = false; fldTitle.Title = "New title"; ...


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


2

if you setup workflow manually you should do these steps: Open List settings Tab on ribbon Click on arrow under workflow settings Click on Add workflow Choose your workflow from the list Setup workflow settings


2

I experienced a similar issue. Upon creation of a new site, the features included in the <WebFeatures> node of the ONet.xml were not activated upon site creation. When navigating to '/_layouts/ManageFeatures.aspx' these features would appear to be activated but their code would not run (no files were placed from modules, breakpoints set in event ...



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