0
我想通過使用StreamWriter的方法序列化一個對象,但不知何故我無法動態定義文件的路徑。StreamWriter參數是不合法的
例子:
public void SerializeToXML(Record aRecord)
{
XmlSerializer serializer = new XmlSerializer(typeof(Movie));
var path = string.Format("@\"{0}\\{1}.xml\"", "C:\\Objects", aRecord.GetHashCode());
TextWriter textWriter = new StreamWriter(path);
serializer.Serialize(textWriter, movie);
textWriter.Close();
}
,然後它說:"Illegal characters in path" on the line :TextWriter textWriter = new StreamWriter(path);
當我passinging它staticaly它wokrs這種格式,但是當我想考績它dymanicaly它不接受它。