SearchAlert in SharePoint 2007
From: palwaipatgmaildotcom
Newsgroups: microsoft.public.sharepoint.portalserver
Subject: SearchAlert in SharePoint 2007
Date: 25 May 2007 07:44:57 -0700
I want to create a SearchAlert in SharePoint 2007 using C# referencing Microsoft.Office.Server, Microsoft.Office.Server.Search and Microsoft.SharePoint dlls. I have used the following code to create one, which creates an alert but does not create in the right place. I mean it gets created in "Intranet > Site Settings > User Alerts". I want it to be created in "Intranet > Search > People and Groups > User Information > My Alerts on this Site".
I think I need to specify the "SearchCenter" web application but donot know where to specify it.
I have looked at the SharePoint table "SchedSubscriptions", it has a wrong value in WebId i.e has Intranet's WebId instead of SearchCenter, WebUrl is empty it should be "/SearchCenter", WebTitle is "Intranet" instead of "Search"
Below is the code -
SPSite spSite = new SPSite("http://localsite:11111");
Query alertQuery = new KeywordQuery(spSite);
alertQuery.QueryText = "test";
SearchAlert searchAlert = new SearchAlert(spSite,
alertQuery);
searchAlert.ChangeType = AlertChangeType.Discovered;
searchAlert.InnerAlert.AlertFrequency = SPAlertFrequency.Daily;
searchAlert.InnerAlert.EventType = SPEventType.Add;
searchAlert.InnerAlert.Title = "Test Search Alert2";
searchAlert.InnerAlert.User.Email = "myname@company.com";
searchAlert.InnerAlert.User.Name = "My Name";
searchAlert.Update();
Thanks
PR
**************************************
From: palwaip
Newsgroups: microsoft.public.sharepoint.portalserver
Subject: Re: SearchAlert in SharePoint 2007
Date: Thu, 05 Jul 2007 19:50:34 -0000
We found the issue with code. When searchAlert.InnerAlert.User.Email is set explicitly it treats it as a System Account and does not even get the initial notification email.
New code is
------------------
SPSite spSite = new SPSite("http://localsite:11111");
Query alertQuery = new KeywordQuery(spSite);
alertQuery.QueryText = "test";
SearchAlert searchAlert = new SearchAlert(spSite,
alertQuery);
searchAlert.ChangeType = AlertChangeType.Discovered;
searchAlert.InnerAlert.AlertFrequency = SPAlertFrequency.Daily;
searchAlert.InnerAlert.EventType = SPEventType.Add;
searchAlert.InnerAlert.Title = "Test Search Alert2";
searchAlert.InnerAlert.User = spSite.OpenWeb().Users["domain\
\userid"];
searchAlert.Update();
After using this code I got the initial notification email and then
later search alert email for the documents that were changed/added
etc..
Good luck,
PR

Posted using