Remove orphaned feature

SP2013


Hello everyone,

Today I’m going to talk about a problem that can happen in a development phase.

When you test your solutions, you may find yourself confronted with this kind of error when deploying:

Sorry, something went wrong

A feature with ID 15/{GUID} has already been installed in this farm. Use the force attribute to explicitly re-install the feature.

First of all, you can delete the feature using this PowerShell command

$feature = Get-SPFeature | ? { $_.Id -eq “{GUID}” }

$feature.Delete()

If you want to do some prevention, you can also run this one which will display all the orphaned feature (meaning they was rectracted unproperly and prevent you for active them again during deployment)

Get-SPFeature | ? { $_.Scope -eq $null }

The tips to display orphaned feature comes from this post: http://sharepoint.stackexchange.com/questions/16525/how-to-remove-orphaned-features thanks to the author!

Hope this helps.

Christopher.

 

Customize alerts

SP2013

Hello everyone,

Today I will talk about a little subtlety in development which I faced recently.

My goal was to change the standard alert message from SharePoint based on custom requirement. For that I had to the code behind to do my test. So I ended up with the implementation of a class inheriting from IAlertNotifyHandler.

Small parenthesis, if you want to do the same, I recommend this article which explains clearly the operation (and I want to thank the author by the way).

http://blogs.msdn.com/b/sharepointdeveloperdocs/archive/2007/12/14/how-to-customizing-alert-emails-using-ialertnotificationhandler.aspx

After a first attempt, I’ve realized that the email received did not looks like the standard mail alert.

In fact, I did not send the entire “header” but just used the “To”. (Again thanks to a passage for the author of this article: http://blogs.msdn.com/b/malag/archive/2008/07/23/alert-emails-not-recognized-by-outlook-as-alert-emails.aspx

Thinking my troubles were ending, I’ve realized that something was also different : the sender’s name!

If we simply use “SPUtility.SendEmail (web, ahp.headers, ahp.body)“, the email address configured in the outgoing mail setup your SharePoint server will be the “sender”, and this is not what is sent by default alerts!

To have exactly the same in your email, you need to change the header “From” as follows.

ahp.headers [“From”] = web.Title + “<” + ahp.headers [“From”] + “>”;

Finally, two things:

1) If you want to test your alerts you have to start the job “Immediate Alerts” for your application via the central administration, “Central Administration -> Monitoring -> review job definition -> Immediate alerts (the one targeting your web application -> run now”. “This job is used for three types of alerts (Immediate, Daily and Weekly)

2) To test your Daily and Weekly alerts, you can easily change the date of mailing via the following PowerShell command

Add-Pssnapin “Microsoft.SharePoint.PowerShell” -ErrorAction SilentlyContinue

$web = Get-SPWeb “yourSiteUrl”

$web.Alerts | select Title,ID,AlertFrequency,User   # this will display every alerts of the web with their ID (used for the next part)

$alert = $web.Alerts | where {$_.ID -eq “PASTE GUID HERE”}

$date=Get-Date

$alert.AlertTime =$date;

$alert.Update();

 

Hope this helps!

 

Christopher