以编程方式从查找字段值获取ID的更好方法是什么?

Tab*_*res 4 c# lookup splistitem sharepoint-2010

当我试图获取id时:

string idValue = item[Lookup].ToString();
Run Code Online (Sandbox Code Playgroud)

我通过示例得到了下一个值:

1#1

我需要这样的价值:

1

实际上这段代码处理了这个要求:

using (SPSite site = new SPSite(context.CurrentWebUrl))
{
    using (SPWeb web = site.OpenWeb())
    {
        //Context list                 
        SPList list = web.Lists[context.ListId];
        SPList child = web.Lists[List]; 
        SPListItem currentItem = list.GetItemById(context.ItemId);
        string updateItems = "";
        int ID = currentItem.ID;

        foreach (SPListItem item in child.Items)
        {
            string idValue = item[Lookup].ToString();
            int partial = idValue.LastIndexOf(";");
            string idPure = idValue.Substring(0, partial);

            if (idPure == ID.ToString())
            {
                item[Field] = Value;
                item.Update();
                updateItems += item.ID.ToString();
            }
        }              

        //Return Items*/
        results["Items"] = updateItems;
        SPWorkflow.CreateHistoryEvent(web, context.WorkflowInstanceId, 0,
            web.CurrentUser, TimeSpan.Zero, "Information",
            "Event from sandboxed, updates: " + updateItems, string.Empty);
    }
}
Run Code Online (Sandbox Code Playgroud)

我想知道一个更好的函数或属性来从查询字段中获取ID.

Gin*_*s K 18

SPFieldLookupValue fieldLookupValue = new SPFieldLookupValue(item["FieldName"].ToString());
int lookupID = fieldLookupValue.LookupId;
Run Code Online (Sandbox Code Playgroud)

干得好 :)