datagrid view (or datagrid) to text file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hey, I'm using a windows form here,and I need to convert a datagridview
(actually its an Inragistics UltraGridView but whatever) to a text file. I
want each row to be in a single line.

I found plenty of tutorials online, but they are only for ASP, and they use
a stringwriter then they call upon System.Web.UI.HtmlTextWriter , and then
Response.write.

I've already got the grid loaded up in a stringbuilder, but how do I export
that stringbuilder to a text file??

here is my code if it will help:

DataSet DSToPrint = new DataSet();

//method returns populated dataset
DSToPrint = myClass.FillDataset();

//make a string builder
StringBuilder str = new StringBuilder();

//fill the string builder with all the rows in the dataset
for (int i = 0; i <= DSToPrint.Tables[0].Rows.Count - 1; i++)
{
for (int j = 0; j <= DSToPrint.Tables[0].Columns.Count - 1; j++)
{
str.Append("[" + DSToPrint.Tables[0].Rows[j].ToString() + "] ");
}
str.Append(Environment.NewLine);
}


now what??
thanks
 
hey, I'm using a windows form here,and I need to convert a datagridview
(actually its an Inragistics UltraGridView but whatever) to a text file. I
want each row to be in a single line.

I found plenty of tutorials online, but they are only for ASP, and they use
a stringwriter then they call upon System.Web.UI.HtmlTextWriter , and then
Response.write.

I've already got the grid loaded up in a stringbuilder, but how do I export
that stringbuilder to a text file??

here is my code if it will help:

DataSet DSToPrint = new DataSet();

//method returns populated dataset
DSToPrint = myClass.FillDataset();

//make a string builder
StringBuilder str = new StringBuilder();

//fill the string builder with all the rows in the dataset
for (int i = 0; i <= DSToPrint.Tables[0].Rows.Count - 1; i++)
{
for (int j = 0; j <= DSToPrint.Tables[0].Columns.Count - 1; j++)
{
str.Append("[" + DSToPrint.Tables[0].Rows[j].ToString() + "] ");
}
str.Append(Environment.NewLine);

}

now what??
thanks


Are you looking for something like this?

System.IO.StreamWriter writer = new
System.IO.StreamWriter(aPath);
writer.Write(myString);
writer.Close();

--Rob W
 
awesome. rob you are the champion!!

Rob Whiteside said:
hey, I'm using a windows form here,and I need to convert a datagridview
(actually its an Inragistics UltraGridView but whatever) to a text file. I
want each row to be in a single line.

I found plenty of tutorials online, but they are only for ASP, and they use
a stringwriter then they call upon System.Web.UI.HtmlTextWriter , and then
Response.write.

I've already got the grid loaded up in a stringbuilder, but how do I export
that stringbuilder to a text file??

here is my code if it will help:

DataSet DSToPrint = new DataSet();

//method returns populated dataset
DSToPrint = myClass.FillDataset();

//make a string builder
StringBuilder str = new StringBuilder();

//fill the string builder with all the rows in the dataset
for (int i = 0; i <= DSToPrint.Tables[0].Rows.Count - 1; i++)
{
for (int j = 0; j <= DSToPrint.Tables[0].Columns.Count - 1; j++)
{
str.Append("[" + DSToPrint.Tables[0].Rows[j].ToString() + "] ");
}
str.Append(Environment.NewLine);

}

now what??
thanks


Are you looking for something like this?

System.IO.StreamWriter writer = new
System.IO.StreamWriter(aPath);
writer.Write(myString);
writer.Close();

--Rob W
 

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

Back
Top