Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

Codes not generate the file properly

Hi,
I don't know why these codes below are not creating any .xml file when I run the project.
                    string FILENAME = Server.MapPath("~") + "..\\..\\xml\\common.xml";
                    ?XmlTextWriter textwrt = new XmlTextWriter(FILENAME, null);
                    textwrt.WriteStartDocument();
                    textwrt.WriteStartElement("Common");
                    textwrt.WriteAttributeString("field1", tb_fld1.Text);
                    textwrt.WriteAttributeString("field2", tb_fld2.Text);
                    textwrt.WriteEndElement();
                    textwrt.Close();

Open in new window

0
HuaMinChen
Asked:
HuaMinChen
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
use this instead:
  string FILENAME = Server.MapPath("~") + "..\\..\\xml\\common.xml";
 XDocument xdoc = new XDocument();
            xdoc.Add(new XElement("common", new XAttribute("field1", 1), new XAttribute("field2", 2)));
            xdoc.Save(FILENAME);

Open in new window

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now