Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将字符串写入位于appdata\local中的xml文件_C#_Xml - Fatal编程技术网

C# 将字符串写入位于appdata\local中的xml文件

C# 将字符串写入位于appdata\local中的xml文件,c#,xml,C#,Xml,我是c#新手,我想知道如何在appdata/local中的xml文件中的特定标记之间编写字符串 我想要达到的目标是: <content> <Package name="gaffersimulations-fale" active="true"/> </content> 使用xml linq: using System; using System.Collections.Generic; using System.

我是c#新手,我想知道如何在appdata/local中的xml文件中的特定标记之间编写字符串

我想要达到的目标是:

<content>
  <Package name="gaffersimulations-fale" active="true"/>
</content>

使用xml linq:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            XElement content = new XElement("content");

            XElement package = new XElement("Package", new object[] {
                new XAttribute("name", "gaffersimulations-fale"),
                new XAttribute("active", "true")
            });
            content.Add(package);
        }
    }
}

嗨,除了顶部的“”之外,没有任何东西被写入文件。我什么都没写。您需要使用:content.Save(“文件名”);