我有一個哈希表,我想從第二個哈希表更新。對於任何匹配的鍵我想複製的價值。我遇到的問題是,當我枚舉散列表鍵並嘗試將每個字符串轉換爲字符串時,我收到關於將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