我有一个哈希表,我想从第二个哈希表更新。对于任何匹配的键我想复制的价值。我遇到的问题是,当我枚举散列表键并尝试将每个字符串转换为字符串时,我收到关于将Guid转换为字符串的异常。那是我想要的字符串。当你使用类似hashtable [“FirstName”]的索引运算符时,我期望FirstName是关键。它可能会在我猜的下面使用Guids,但我需要脱离关键字的字符串,关键值。如何获得哈希表项的密钥
private void UpdateSharePointFromInfoPath(Hashtable infopathFields)
{
// Go through all the fields on the infopath form
// Invalid Cast Exception Here
foreach (String fieldName in infopathFields.Keys)
{
// If the same field is on sharepoint
if (workflowProperties.Item.Fields.ContainsField(fieldName))
{
// Update the sharepoint field with the new value from infopath
workflowProperties.Item[fieldName] = infopathFields[fieldName];
}
}
// Commit the changes
workflowProperties.Item.Update();
}
编辑 我不创造任何这些哈希表的。键有字符串的地方,因为我可以把字段名称放在下面,并获得字段的值。我试图让做,每场以下的简写方式:
workflowProperties.Item["FirstName"] = infopathFields["FirstName"];
workflowProperties.Item["LastName"] = infopathFields["LastName"];
workflowProperties.Item["Address"] = infopathFields["Address"];
workflowProperties.Item["DOB"] = infopathFields["DOB"];
ect...
编辑 有人说,该哈希表使用的GUID,但它也显然有其他内部字符串我不会能够做到infopathFields [“FirstName”]。这是我想要的字符串中的值。
我不知道为什么你的Guids和字符串混在一起,但你为什么要用旧的Hasht能够上课而不是2.0以上的词典? – 2009-12-04 17:06:49
我不创建哈希表。 – 2009-12-04 17:22:43
我投了弃权票,因为我不赞赏你侮辱那些试图帮助你的人。 – 2009-12-04 18:07:57