Sharepoint Services 3.0:itemAttachmentAdded方法:如何在将附件添加到列表项后更新列

时间:2012-09-26 00:28:17

标签: c# wss-3.0

我有一个名为“NameList”的自定义列表。我只有两列。说出名字(单行/文本)和姓氏(单行/文本)。我想要做的是当用户在列表中添加“新项”时。他只需要填写第一个名字。然后,他使用“附加文件”选项添加附件,然后单击“确定”。当他点击OK时,我希望姓氏自动更新为“Matthews”。因为我想要完成的是在添加atachment时能够更新列(字段)。这是我的代码。有人能告诉我哪里出错了。

它也不起作用。我也是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

0 个答案:

没有答案
相关问题