SharePoint : Migrating User Alerts

buy Lyrica 50 mg When you do Version to Version (V2V) upgrade for your SharePoint domain may change (for whatever reason) or in case of FBA your membership provider name gets changed. I am not going to get into the details why that would happen and how to handle your upgrade in those scenarios.

What I am going to talk about is one big issue that will occur when you run into the above scenario. That is issue is all the user Alerts will not be displayed. When I say not be displayed what I mean is that Alerts will be upgraded (I am assuming you kept your Portal URL the same) but when users login to the portal they will not see the Alerts. Why is that, you asked? Well before you start blaming SharePoint, let me tell you, that SharePoint is doing its job right. Each Alert have User and UserID assigned to it. The momentum Domain name changes or your membership provider changes, New UserID gets created for the same user and for SharePoint there is no Alerts set for that user and hence it will not display any Alerts. Unfortunately SharePoint does not have face recognition technology built into it… YET.. J

If you run into above scenario then the solution is simple. I mean you still have to code but given the fact you landed on this Blog, your job becomes that much easier. Here is the sample code which shows how you can migrate Alert from one user to another.

 

using (SPSite site = new SPSite(textBox1.Text.Trim())){

      foreach (SPWeb web in site.AllWebs){

          SPUser user = web.EnsureUser(@”i:0#.f|contoso\brianc”);

          SPUser user1 = web.EnsureUser(@”i:0#.f|litwareinc\brianc”);

         SPAlertCollection alertColl = user.Alerts;

          foreach (SPAlert alert in alertColl){

                alert.User = user1;

                alert.Update();

           }

           web.Dispose();

​        }

 }

​In real life scenario you will be looping through you SiteUsers and making this change.