Hot answers tagged

14

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); } not using ...


12

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


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


8

Get-SPWebApplication xxx | Get-SPSite -Limit ALL | % {Enable-SPFeature "xxx" -Url $_.Url}


8

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


8

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


6

If the assembly contains any event or feature receivers then the deployment target should be Global Assembly Cache. And if you deploy the solution using a command line then you should start a new instance of that before activating the feature (this is most important when you get to upgrading) as an old version of the dll can't be unloaded.


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


6

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


6

What i usually do is very lo-tech: i use NotePad++ or UltraSeek's "Search In Files" functionality to search for the GUID in question in the FEATURES folder in the 12 hive. That gives me both where it is defined and where it is used.


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

This error mostly occurs when you go wrong with the name of the feature. Activate it using GUID instead, should help!


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


4

Why dont you just add the feature to SiteFeatures or WebFeatures element of onet.xml ? It is what it is there for :) The features are executed synchronous, so only in very rare occasions have I experienced race conditions.


4

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


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

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

I think you should check this: Removing Provisioned Files from SharePoint During Feature Deactivation


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

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

Here is the C# version of Anders answer as it was not as straightforward as I would have thought. public static void SetFormJSLink(this SPList list, PAGETYPE formBaseView, string jsLinkUrl) { var file = list.ParentWeb.GetFile(list.Forms[formBaseView].Url); file.CheckOut(); using (var manager = ...


4

I have faced the same situation many times. I used a tool called Feature Admin. It shows any features that are isolated and cannot be used including error occured. You can delete the unwanted or error occurred features through it.


3

function Deactivate-SPFeature { param ($FeatureID, $SiteUrl, $WebApplicationUrl) $Feature = Get-SPFeature -Identity $FeatureID -ErrorAction SilentlyContinue $IsActiveFeature If ($Feature -eq $null) { Write-Warning "The specified feature ($FeatureID) was not found." return } If ($Feature.Scope -eq ...


3

make sure the solution deployment job was finished before you activate the feature. have a look at this blog: Programmatically waiting on SharePoint Solutions to deploy


3

Have you tried viewing logs with ULS viewer? I think your problem might be that you are using SPContext.Current in a timer job.


3

You should get site url as below. string siteUrl = this.Properties["SiteURL"].ToString(); and use below code to get current web in timerjob. using (SPSite site = new SPSite(siteUrl)) { using (SPWeb CurrentWeb = site.OpenWeb()) { // Write code here } }


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


3

Ok so the Get-SPFeature works differently depending on what parameters you pass it. The following line is asking which features are enabled at the Web Scoped level. $webFeature = Get-SPFeature -Web $spSiteCollection | Where-Object.... However, if you want to see if your feature is installed then you need to use Get-SPFeature without passing any scope to ...


3

It seems that for JSLink to work on the display/new/edit forms you need to set the JSLink on the webpart used in the forms, not directly on the form itself. The following PowerShell code works for the new form on a blog post and should be easy to adopt to your needs in C#: $web = Get-SPWeb "http://myportal" $file = $web.GetFile("Lists/Posts/NewPost.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 ...



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