路径问题,怎样设置路径才能将创建的xml文件保存在项目中
怎样设置路径才能将创建的xml文件保存在项目中,代码中path的值设置的不对,应该怎样改啊?
代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace xml_test2
{
class Program
{
public static string path="D:";
public static void CreateDocument()
{
XDocument xdoc = new XDocument( new XDeclaration("1.0","utf-8","yes") , new XElement("Root","root") );
xdoc.Save(path);
}
public static void CreateCategories()
{
XElement root = new XElement("Categories",
new XElement ("Category",
new XElement ("CategoryID",Guid.NewGuid()),
new XElement("CategoryName", "Beverages")
),
new XElement ("Category",
new XElement ("CategoryID",Guid.NewGuid()),
new XElement("CategoryName", "Condiments")
),
new XElement ("Category",
new XElement ("CategoryID",Guid.NewGuid()),
new XElement("CategoryName", "Confections")
)
);
root.Save(path);
}
static void Main(string[] args)
{
Program.CreateDocument();
Program.CreateCategories();
}
}
}