Solved

Codes not generate the file properly

Posted on 2013-06-25
1
197 Views
Last Modified: 2013-06-30
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
Comment
Question by:HuaMinChen
1 Comment
 
LVL 42

Accepted Solution

by:
sedgwick earned 110 total points
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now