<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Create a new alert for a SharePoint list</title>
	<atom:link href="http://www.emptycache.com/blog/?feed=rss2&#038;p=67" rel="self" type="application/rss+xml" />
	<link>http://www.emptycache.com/blog/?p=67</link>
	<description>a developer&#039;s blog</description>
	<lastBuildDate>Mon, 27 Apr 2009 06:44:01 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: SharePoint 2007&#8217;s problems &#171; Huynhvothinh&#8217;s Weblog</title>
		<link>http://www.emptycache.com/blog/?p=67&#038;cpage=1#comment-3214</link>
		<dc:creator>SharePoint 2007&#8217;s problems &#171; Huynhvothinh&#8217;s Weblog</dc:creator>
		<pubDate>Wed, 04 Feb 2009 02:51:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.emptycache.com/blog/2008/04/17/create-a-new-alert-for-a-sharepoint-list/#comment-3214</guid>
		<description>[...] -http://www.emptycache.com/blog/2008/04/17/create-a-new-alert-for-a-sharepoint-list/ [...]</description>
		<content:encoded><![CDATA[<p>[...] -http://www.emptycache.com/blog/2008/04/17/create-a-new-alert-for-a-sharepoint-list/ [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pamela Willox</title>
		<link>http://www.emptycache.com/blog/?p=67&#038;cpage=1#comment-3209</link>
		<dc:creator>Pamela Willox</dc:creator>
		<pubDate>Fri, 26 Sep 2008 02:49:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.emptycache.com/blog/2008/04/17/create-a-new-alert-for-a-sharepoint-list/#comment-3209</guid>
		<description>Excellent post Adam. I hope you can help me!
I&#039;ve created an item event handler so that when someone posts an item to a list, an alert is created on that item (if it&#039;s the first post i.e fileSystemObjectType folder).
It works well if it&#039;s a site administrator creating the item, but when it&#039;s a user with member permissions, I have a problem. When it tries to set the alert template name 
I get a permission denied error.

I have tried to open the site with a user token to impersonate the site collection administrator but still having the same issue.
Here is the method for the alert up to the point it fails:

public void CreateAlert(SPWeb myWeb, SPList list, SPListItem item, string alertTitle, SPUser alertUser, bool notify)
        {
            try
            {
                    SPUserToken siteAdminToken = GetUserToken(myWeb.Url.ToString(), &quot;siteadmin&quot;);
                    using (SPSite site = new SPSite(myWeb.Site.ID, siteAdminToken))
                    {
                        SPWeb alertsWeb = site.OpenWeb(myWeb.ID);
                        SPList alertList = alertsWeb.Lists[list.ID];
                        SPListItem alertListItem = alertList.GetItemById(item.ID);
                        SPAlertCollection alerts = alertsWeb.Alerts;
                       
                        // get the lists alert template and apply that to the new alert
                        SPAlertTemplate alertTemplate = alertList.AlertTemplate;
                        alertTemplate.Name = alertList.AlertTemplate.Name;
...
}

Can you shed any light?

Regards,
Pam</description>
		<content:encoded><![CDATA[<p>Excellent post Adam. I hope you can help me!<br />
I&#8217;ve created an item event handler so that when someone posts an item to a list, an alert is created on that item (if it&#8217;s the first post i.e fileSystemObjectType folder).<br />
It works well if it&#8217;s a site administrator creating the item, but when it&#8217;s a user with member permissions, I have a problem. When it tries to set the alert template name<br />
I get a permission denied error.</p>
<p>I have tried to open the site with a user token to impersonate the site collection administrator but still having the same issue.<br />
Here is the method for the alert up to the point it fails:</p>
<p>public void CreateAlert(SPWeb myWeb, SPList list, SPListItem item, string alertTitle, SPUser alertUser, bool notify)<br />
        {<br />
            try<br />
            {<br />
                    SPUserToken siteAdminToken = GetUserToken(myWeb.Url.ToString(), &#8220;siteadmin&#8221;);<br />
                    using (SPSite site = new SPSite(myWeb.Site.ID, siteAdminToken))<br />
                    {<br />
                        SPWeb alertsWeb = site.OpenWeb(myWeb.ID);<br />
                        SPList alertList = alertsWeb.Lists[list.ID];<br />
                        SPListItem alertListItem = alertList.GetItemById(item.ID);<br />
                        SPAlertCollection alerts = alertsWeb.Alerts;</p>
<p>                        // get the lists alert template and apply that to the new alert<br />
                        SPAlertTemplate alertTemplate = alertList.AlertTemplate;<br />
                        alertTemplate.Name = alertList.AlertTemplate.Name;<br />
&#8230;<br />
}</p>
<p>Can you shed any light?</p>
<p>Regards,<br />
Pam</p>
]]></content:encoded>
	</item>
</channel>
</rss>
