StreamWriter Creates File But Does not Add the Passed Text.


John Tyce

My stream writer is creating the file, but writes no text in it.

if(MyDataSet.Tables["USER_QUERYTABLE"] != null)



FileStream fs = new FileStream(@"C:\DISWin\Report\userdata.xml",FileMode.Open,FileAccess.Read);

//FileStream txtFS = new FileStream(@"C:\DISWin\Report\OutPut.txt",FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);

StreamWriter MyWriter = new StreamWriter(@"C:\DISWin\Report\OutPut.txt"); //(also tried passing the above FileStream her instead of path)

XmlTextReader xtr = new XmlTextReader(fs);

XmlDocument doc = new XmlDocument();


XmlNodeList nodeLst;

string strCol = null;

int n = 0;

foreach(string item in mCol_Name)


if(item != null && item != "")


n = item.IndexOf(",",0);

string tag = item.Remove(n,1);

tag = tag.Trim();

nodeLst = doc.GetElementsByTagName(tag);

foreach(XmlNode node in nodeLst)


strCol = node.InnerText.ToString();

n = strCol.Length;

strCol = strCol.Remove(10,(n-10));

strCol = tag + " " + strCol;

MyWriter.WriteLine(strCol); (this produces no text in the output.txt file)








Jon Skeet [C# MVP]

John Tyce said:
Thanks, but I figured it out.

So what was the problem? If you could say what you had to change, it
could help someone else with the same problem who may find your post
through in the future.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question