如何在winforms C#中使用openfiledialog反序列化XML文件? [英] How can I deserialize XML file with openfiledialog in winforms C#?

查看:79
本文介绍了如何在winforms C#中使用openfiledialog反序列化XML文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要对我拥有的几个文件进行反序列化,问题是它只有一个,(我想这是因为在代码中,序列化器XML中有一部分,它指定了反序列化的文件路径,FileStream FS = new FileStream("
file.xml,fileMode.Open,FileAccess.Read);,表示路径"file.xml",我需要替换为你的文件路径在openfiledialog窗口中选择,我已经尝试用"openfiledialog1。FileName"替换它,但是
它向我显示以下错误"System.InvalidOperationException:'XML文档中的错误(0,0)'内部异常XmlException:缺少根元素"。

I need to deserialize several files that I have, the problem is that it is only one, (I suppose it is because in the code, there is a part in the serializator XML, in which it specifies the file path to Deserialize, FileStream FS = new FileStream (" file.xml, fileMode.Open, FileAccess.Read) ;, indicates the path "file.xml", and I need to be replaced by the path of the file you choose in an openfiledialog window, I have already tried to replace it with "openfiledialog1. FileName "but it shows me the following error" System.InvalidOperationException: 'Error in the XML document (0,0)' Inner exception XmlException: The root element is missing ".

推荐答案

您好,

>> 我需要替换为您在openfiledialog窗口中选择的文件的路径,

您是如何用o替换文件路径的? penFileDialog?

How did you replace the file path with openFileDialog?

请试试这个:

    if (openFileDialog1.ShowDialog() == DialogResult.OK)
    {
        FileStream FS = new FileStream(openFileDialog1.FileName, fileMode.Open, FileAccess.Read);
        //...
    }

问候,

Frankie


这篇关于如何在winforms C#中使用openfiledialog反序列化XML文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆