「NameList」というカスタム リストがあります。2 つの列しかありません。名 (1 行 / テキスト) と姓 (1 行 / テキスト) を言います。私がやろうとしているのは、ユーザーが「新しいアイテム」をリストに追加したときです。彼は名前を入力するだけです。次に、[ファイルを添付] オプションを使用して添付ファイルを追加し、[OK] をクリックします。彼が [OK] をクリックすると、姓が自動的に更新されて "Matthews" と表示されるようにします。私が達成しようとしているのは、添付ファイルが追加されたときに列 (フィールド) を更新できるようにすることです。これは私が持っているコードです。誰かが私がどこで間違っているのか教えてもらえますか?
また、少し動作していません。また、SharePoint 開発の初心者でもあり、ここに来る前にできる限り多くの情報を検索しました。姓の列は入力されません。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
namespace UpdateNameList
{
public class NameListItemEventReceiver : SPItemEventReceiver
{
public override void ItemAttachmentAdded(SPItemEventProperties properties)
{
base.ItemAttachmentAdded(properties);
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite("http://cse-sp01/sites/SPPilot"))
{
using (SPWeb web = site.OpenWeb())
{
try
{
web.AllowUnsafeUpdates = true;
SPList list = web.Lists["NameList"];
int listItemId = properties.ListItemId;
SPListItem listItem = list.Items.GetItemById(listItemId);
listItem["Last Name"] = "Matthews";
listItem.Update();
web.AllowUnsafeUpdates = false;
}
catch (Exception ex)
{
properties.ErrorMessage = "Something went wrong??";
}
}
}
});
}
catch (Exception ex)
{
properties.Cancel = true;
properties.ErrorMessage = "Error encountered";
}
}//End of Void ItemAttachmentAdded
}
}//End of namespace