Tag Info

Hot answers tagged

11

I came across this link by Josh Gaffey that describes how to set the welcome page for a publishing site. The code I used is: ... // Create publishing page if (bPageCreated) { using (SPSite site = new SPSite(p_sSubSiteUrl)) { using (SPWeb web = site.OpenWeb()) { PublishingWeb publishingWeb = null; if ...


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


7

Usually this happens if you have feature activated event receiver and use http context in code somehow (accessing to SPContext.Current or creating web part, that might use internally Http context). When you activate your feature through UI, Http context is not null and all may work as expected, but when activating through PS or stsadm Http context is null ...


6

It’s better to use the Delete() method of SPWeb.Lists instead of using the Delete() method on the SPList because the latter doesn't delete lists properly sometimes. Try something like: SPWeb mySite= SPContext.Current.Web; SPList myCustomList = mySite.Lists["MyCustomList"]; mySite.Lists.Delete(myCustomList.ID); mySite.Update();


5

I'm pretty sure that if your assemblies contain feature receivers then they need to be installed into the GAC. There is a post about it here, but in my opinion it doesn't give a good explanation why. My theory is that when you attach a feature receiver to a feature, the assembly needs to be globally available, since FeatureInstalled/Activated etc can be ...


5

Remove feature receiver Clean solution Close Visual Studio Delete SharePoint project's obj folder in Windows Explorer Delete SharePoint project's bin folder in Windows Explorer Open Visual Studio and re-add feature receiver Start Debugging


5

how about; warning: your feature needs to be scoped as web for it to work obviously ;) public override void FeatureActivated(SPFeatureReceiverProperties properties) { // No need to dispose the web istance, as indicated in the "Do not dispose" guidance SPWeb web = (SPWeb) properties.Feature.Parent ClassOfMine.doYourStuff(web); } if not then ...


4

Isn't too difficult really, in the FeatureActivated method, you just create a new SPieldLookup (using SPWeb.Fields.AddLookup() for the SPSite's RootWeb), and set the properties for the SPFieldLookup as required. First time doing it? Bit tricky if you've never made a FeatureReceiver before, let me know if you need a tutorial do that, and here's some sample ...


4

According to this post How to debug Feature Receiver you can add this line of code to the method you are trying to debug: System.Diagnostics.Debugger.Launch();


4

If you mean EventReceiver for the feature then you need to attach to the VSSHost process of Visual Studio 2010 which is actually running the code on activation during an F5 deploy. Another approach would be to set the solution to 'no activation' and then attach the debugger to the process after a F5, activate the feature, now it should hit the feature code. ...


4

The FeatureInstalled method is called when the WSP is loaded into the Farm and the Feature files are copied into the 12 hive. This is done in Central Administration or via the command line (Powershell or STSADM). Because of this, there is no website Context to speak of, no site collection or no SPWeb.


4

Add a page to the Pages library of your site, name it HomePage.aspx. Add whatever webpart etc. you need to it. Then, in the site settings of the site (_Layouts/AreaWelcomePage.aspx) set the url to point to your custom homepage. Now when someone enters the url of your site (ie. http://mycoolportal.company.local) IIS / SharePoint will point the browser to the ...


4

If you know the name of the feature, you can retrieve the feature's definition ID by iterating the SPFeatureDefinitionCollection. Guid yourGuid; foreach (SPFeatureDefinition featureDef in web.FeatureDefinitions) { if (featureDef.DisplayName == "YourTitle" && featureDef.Scope == SPFeatureScope.Web) // Check the scope just to be safe { ...


3

This seems to me an unnecessarily confusing way of going about things. If you have a feature that depends on another solution I would recommend creating a solution dependency between the "dependency" solution and the solution that contains the dependent feature. Unfortunately that wasn't available in SP2007, so you may have to do something in your deployment ...


3

Looks like you have some kind of threading issue here. Standard PowerShell runs each pipeline/line on different threads while the SharePoint PowerShell console runs all in the same thread. Try starting a std PowerShell console and write $Host.Runspace.ThreadOptions = "ReuseThread" And then run your script again and report back. Also make sure that you ...


3

If you have SP2 installed in your environment you could run the preupgradecheck via STSADM e.g. STSADM -o preupgradecheck This will generate a report for you which among other things will list all the features in your environment and give you the feature name and GUID. http://technet.microsoft.com/en-us/library/dd789638.aspx


3

By design ListAdded can be hosted by SPWeb or SPSite only as documented here. So Feature Stapling cannot be avoided if you want to enforce that across the farm. UPDATE: As per MSDN Documentation, If the Receivers tag has no ListTemplateId or ListUrl attribute, the event receiver is registered at the same scope as the Feature. Which means you should not use ...


3

some good practices are: use feature activation dependencies to control multiple hidden features activations with single master feature clean up web parts on deactivating for web parts added by feature activation some bad practices are: rely on feature activation order using dependencies clean up data structures (lists/sites) on feature deactivation ...


3

The issue is the lists get created after the feature stapling is called in the Site Collection creation process. The My Site is a new Site Collection, not a new subsite, that's why the event receivers don't fire and the manual activation works. I have used a thread pool solution like the one in the link below to delay the execution until the lists have been ...


3

You mention that you already have PowerShell scripts to deploy your packages. That is a good start. I would recommend starting from Gary Lapointe's excellent Deploy-SPSolution scripts for this purpose. You should make sure you have configured feature dependencies appropriately for your solution, this will ensure no one can make mistake and activate them in ...


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

A really good explanation is already been given on this blog, so I would suggest you to look at it features-with-powershell/ Possibly Duplicate Question EDIT detect if a feature is deployed or not detecting-solution-deploying-status Edit 2 Code of checking if a feature is activated or not PS C:\Users\omlin> $featureGuid = "PUT-GUID-HERE" PS ...


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 can use feature stapling to achieve this. You just deploy a simple element file in a feature and activate it at the web application level. <?xml version="1.0" encoding="utf-8"?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <FeatureSiteTemplateAssociation Id="the guid of the feature to staple to new sites" ...


2

I recommend Anders' approach. If the features still can't be found then there are tools by Stefan Gossner that will help you clean them up: WssAnalyzeFeatures: verifies that the feature definition files for all installed features are present on the file system WssRemoveFeatureFromSite: removes the feature from the site or site collection completely if ...


2

Well, given enough time, you can figure things out with SharePoint... Here is what appears to be happening. In ONET, I also had CAML to provision some lists (here is the Announcements one): <List FeatureId="00BFEA71-D1CE-42de-9C63-A44004CE0104" Type="104" Title="$Resources:core,announceList;" ...


2

The order that features are provisioned are: first OOB site collection (site) scoped features are activated in the order specified in onet.xml, then site collection scoped stapled features are activated in random order (beware of race conditions). Then site (web) scoped features are triggered in the order defined in onet.xml, now site scoped stapled features ...


2

I have a bad habit of activating web application features on the wrong web app. I would double check that the correct web application is selected from the toolbar on the "Manage Web Application Features" page. If the problem still persists, you could try using stsadm to deactivate/reactivate the standard web application feature with the -force parameter.


2

The difference is the scope of the Feature, which depends on the content of the feature. Here's a starter for reading material about this: http://weblogs.asp.net/soever/archive/2007/05/03/sharepoint-features-elements-scope-and-other-info.aspx


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



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