Tag Info

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


7

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


6

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


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

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

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

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"]; ...


3

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();


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

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


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

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

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


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

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

The WebProvisioned method of the SPWebEventReceiver does not fire when a site collection is created. This is confirmed by the WebProvisioned Method MSDN page. Depending of what your custom code does, it is best to use feature stapling either scoped to Site or Web against the site template you are using.


2

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


2

You could use SystemUpdate instead of ProcessBatchData. False should mean modified date doesn't change: SPListItem item = ???; item["myField"] = "my value"; item.SystemUpdate(false); Of course, this means you have to update each item one at a time instead of the batch process which may lead to performance issues. See also, how to temporarily disable ...


2

The ReceiverAssembly should be the Fullname of the assembly FeatureBuilder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx If developing using SharePoint templages in Visual Studio 2010 use $SharePoint.Project.AssemblyFullName$


2

I dont think you will need Event Receiver for your purpose, please find this thread of stackexchange SP 2010 Custom Access Denied Pages For help with command you may find this MSDN Article helpful For details steps please go through this Customize the Access Denied Page


2

I'm not sure this will work, but I would try this: public override void FeatureActivated(SPFeatureReceiverProperties properties) { //Get webapplication SPWebApplication webApplication = properties.Feature.Parent as SPWebApplication; //Get current user from any sitecollection and rootweb SPUser user = ...


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


1

Since you are hiding the other features, this is a candidate ripe for Activation Dependencies (the hidden ones will auto-activate during the activation of the visible master feature) This would help you avoid having to write the above code. Visual Studio has an interface for specifying this (I know I'm likely telling you things you already know) but.. if ...


1

I would go for Deepu's explanation in general. For more details rather, you need to consider, assuming you build a WSP package via VS2010: Your own custom list? - if yes, you could do it declaratively in the List Definition (is a bitch to do that XML declaratively for the views - but is doable). Another list? - use Deepu's explanation with the caveat ...


1

Couple of things: You should be updating SPContentType.FieldLinks, and not SPContentType.Fields. The latter is only a construct that represents the merge between the field's list definition and any specific modifications for that content type in that list. Try using SPField.Update(boolean) to propagate changes down the hierarchy from the site-level ...


1

You can create custom property for the feature. In your Feature CAML you can define <Feature id...> <Properties> <Property Key="ConnectionString" Value="String"/> </Properties> </Feature> Then use this code in the feature receiver SPFeatureReceiverProperties.Feature.Properties["ConnectionString"] In this case ...



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