using System;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;
using System.Data;
using Microsoft.SharePoint.Administration;
namespace Discuss.EventReceiver1
{
public class EventReceiver1 : SPItemEventReceiver
{
/// <summary>
/// An item was updated.
/// </summary>
public override void ItemUpdated(SPItemEventProperties properties)
{
if (properties.ListTitle == "Team Discussion")
{
this.DisableEventFiring();
base.ItemUpdated(properties);
string Title = string.Empty;
//Int32 id = Convert.ToInt32(properties.ListItemId);
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPWebApplication webApp = SPWebApplication.Lookup(new Uri(""));
{
foreach (SPSite site in webApp.Sites)
{
using (SPWeb web = site.OpenWeb())
{
try
{
SPList listMessageBrd = web.Lists[properties.ListTitle];
SPListItem lstitem = properties.ListItem;
SPListItemCollection lstcoll = web.Lists[properties.ListTitle].Items;
Title = properties.ListItem["Title"].ToString();
SPFieldMultiLineText field = (SPFieldMultiLineText)lstitem.Fields["Body"];
string text = field.GetFieldValueAsText(lstitem["Body"]);
//I am not getting value of body in string text. whenever I take simple multiple line of text column I got body value. but in discussion board it is not working. we got only previous value in body not current value.
SPSiteDataQuery dataQuery = new SPSiteDataQuery();
dataQuery.Webs = "<Webs Scope=\"SiteCollection\">";
dataQuery.Lists = "<Lists ServerTemplate=\"108\"
/>";
dataQuery.ViewFields = "<FieldRef Name=\"Title\"
Nullable=\"TRUE\" Type=\"Text\"/>";
dataQuery.ViewFields = "<FieldRef Name=\"Body\"
Nullable=\"TRUE\" Type=\"Text\"/>";
dataQuery.ViewFields = "<FieldRef Name=\"ContentType\"/>";
string where = "";
where = "<Where>";
if (Title != "")
{
where += "<Eq>";
where += "<FieldRef
Name=\"Title\"/>";
where += "<Value
Type='Text'>" + Title + "</Value>";
where += "</Eq>";
}
where += "</Where>";
dataQuery.Query = where;
DataTable dt = web.GetSiteData(dataQuery);
foreach (DataRow row in dt.Rows)
{
Guid lstid = new Guid(row.ItemArray[0].ToString());
SPList list = web.Lists[lstid];
SPListItem item = list.GetItemById(Convert.ToInt16(row[2]));
SPListItemreply = Microsoft.SharePoint.Utilities.SPUtility.CreateNewDiscussionReply(item);
reply["Body"]
= text;
//reply[SPBuiltInFieldId.Body]
= (string)lstitem["Body"];
reply.Update();
}
}
catch (Exception Ex)
{
throw Ex;
properties.ErrorMessage = Ex.Message;
}
}
}
}
});
}
}
}
}
please help me or suggest me some Idea.
Thanks
Rajiv Kumar
SharePoint System Analyst
Atos,Pune