本文介绍了序列在C#不使用文件系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的字符串二维数组,我想将它塞进在MOSS的SPFieldMultiLineText。这映射到一个NTEXT数据库字段。
我知道我可以序列化到XML并存储到文件系统,但我想没有触及文件系统的序列化。
公共覆盖无效ItemAdding(SPItemEventProperties属性)
{
//生成数组
名单,LT;清单<串GT;>矩阵=新的List<名单,LT;串GT;>();
/ *
*填充数组被剪断,做工精细
* /
//现在坚持这个矩阵进入该领域在我的列表项
properties.AfterProperties [ myNoteField] =矩阵; //引发错误
}
看起来我应该能够做这样的事
XmlSerializer的S =新的XmlSerializer(typeof运算(列表<名单<串>>));
properties.AfterProperties [myNoteField] = s.Serialize.ToString();
但是,这并不工作。我发现所有的例子演示写入一个文本文件。
解决方案
的StringWriter outStream =新的StringWriter();
XmlSerializer的S =新的XmlSerializer(typeof运算(列表<名单,LT;串GT;>));
s.Serialize(outStream,MyObj中);
properties.AfterProperties [myNoteField] = outStream.ToString();
I have a simple 2D array of strings and I would like to stuff it into an SPFieldMultiLineText in MOSS. This maps to an ntext database field.
I know I can serialize to XML and store to the file system, but I would like to serialize without touching the filesystem.
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
}
Looks like I should be able to do something like this:
XmlSerializer s = new XmlSerializer(typeof(List<List<string>>));
properties.AfterProperties["myNoteField"] = s.Serialize.ToString();
but that doesn't work. All the examples I've found demonstrate writing to a text file.
解决方案
StringWriter outStream = new StringWriter();
XmlSerializer s = new XmlSerializer(typeof(List<List<string>>));
s.Serialize(outStream, myObj);
properties.AfterProperties["myNoteField"] = outStream.ToString();
这篇关于序列在C#不使用文件系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!