我已经在 SharePoint 中使用 C# 编码创建了事件接收器。当项目应该匹配时已经有了。它显示这样的按摩是我的代码..
public override void ItemAdding(SPItemEventProperties properties)
{
base.ItemAdding(properties);
SPList oList = null;
string strCarName = string.Empty;
using (SPWeb web = properties.Web)
{
oList = web.Lists["Cars"];
string dropdwnvalue = web.Lists[properties.ListId].Fields["CarName"].InternalName;
String lookupFieldStringValue = Convert.ToString(properties.AfterProperties[dropdwnvalue]);
SPListItem item = oList.Items[Convert.ToInt32(lookupFieldStringValue) - 1];
strCarName = Convert.ToString(item["LinkTitle"]);
}
string strStartdate = Convert.ToString(properties.AfterProperties["EventDate"]);
SPQuery existingItemsQuery = new SPQuery();
existingItemsQuery.Query = "<Where><And><Eq><FieldRef Name='EventDate'/><Value Type='DateTime'>" + strStartdate + "</Value></Eq><Eq><FieldRef Name='Car_x0020_Name'/><Value Type='Lookup'>" + strCarName + "</Value></Eq></And></Where>";
SPListItemCollection existingItems = properties.List.GetItems(existingItemsQuery);
if (existingItems.Count >= 1)
{
properties.Cancel = true;
properties.ErrorMessage = "Item is already exists";
properties.Status = SPEventReceiverStatus.CancelWithError;
// ClientScript.RegisterStartupScript(typeof(Page), "test", "<script>alert('Hello');return false;</script>");
}
输出:-
项目已存在。该项目一天只添加一次。我不能再添加另一个项目。但我想在一天的更改时间添加另一个项目
任何人都可以帮助我。