【发布时间】:2009-12-04 16:59:53
【问题描述】:
我有一个要从第二个哈希表更新的哈希表。对于任何匹配的键,我想将值复制过来。我遇到的问题是,当我枚举哈希表键并尝试将每个键转换为字符串时,我收到一个关于将 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...
编辑 据说哈希表使用Guids,但它显然也有一个字符串,否则我将无法执行infopathFields [“FirstName”]。这是我想要传入的字符串上的值。
【问题讨论】:
-
我不确定为什么您的 Guid 和字符串会混淆,但您为什么使用旧的 Hashtable 类而不是 2.0 及以上版本的字典?
-
我不创建哈希表。
-
我投了反对票,因为我不欣赏你侮辱那些试图帮助你的人。