Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Alert Migration and Creation

$
0
0

Hi - I am about to create a console app to iterate through ALL Alerts in a SharePoint instance and save as XML(?).

The second task is to create a console app which reads this XML file and recreates the Alerts if a match (list) is found (in another site).

I have started my first app to retrieve alerts - what I'd like to know is if this is the best approach and if anyone can advise on the XML element of my task. I have no idea how to create the second app yet so lets start with the first!

Thanks in advance for any help you can offer.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
namespace AlertMigration
{
    class Program
    {
        private static SPSite _site = null;
        private static SPWeb _currentWeb = null;
        private static SPUserCollection _users = null;
        private static string _siteUrl;
        private static void Main(string[] args)
        {
            _siteUrl = "x";
            _site = new SPSite(_siteUrl);
            _currentWeb = _site.OpenWeb();
            _users = _currentWeb.Users;
            Console.WriteLine(("STARTED"));
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                try
                {
                    foreach (SPUser user in _users)
                    {
                        SPAlertCollection collAlerts = user.Alerts;
                        Console.WriteLine("Alerts for the User : " + user.Name);
                        foreach (SPAlert alrt in collAlerts)
                        {
                            Console.WriteLine(alrt.Item.Title + "–>" + alrt.AlertFrequency);
				// TODO: Start building XML file
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            });
            Console.ReadLine();
        }
    }
}


Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>