gpt4 book ai didi

c# - 在不使用文件系统的情况下在 C# 中进行序列化

转载 作者:IT王子 更新时间:2023-10-29 04:18:06 24 4
gpt4 key购买 nike

我有一个简单的二维字符串数组,我想将其填充到 MOSS 中的 SPFieldMultiLineText 中。这映射到一个 ntext 数据库字段。

我知道我可以序列化为 XML 并存储到文件系统,但我想在不接触文件系统的情况下进行序列化。

public override void ItemAdding(SPItemEventProperties properties)
{
// build the array
List<List<string>> matrix = new List<List<string>>();
/*
* populating the array is snipped, works fine
*/
// now stick this matrix into the field in my list item
properties.AfterProperties["myNoteField"] = matrix; // throws an error
}

看起来我应该可以做这样的事情:

XmlSerializer s = new XmlSerializer(typeof(List<List<string>>));
properties.AfterProperties["myNoteField"] = s.Serialize.ToString();

但这行不通。我找到的所有示例都演示了如何写入文本文件。

最佳答案

StringWriter outStream = new StringWriter();
XmlSerializer s = new XmlSerializer(typeof(List<List<string>>));
s.Serialize(outStream, myObj);
properties.AfterProperties["myNoteField"] = outStream.ToString();

关于c# - 在不使用文件系统的情况下在 C# 中进行序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/302821/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com