Replies |
T.Saravanan
Posted on: 6/4/2012 4:00:43 PM
|
Level: Silver | Status: [Member] [MVP] | Points: 25
|
Hi,
try the below code...
// Here I am using DataTable instead of GridView.
public void WriteTextFile(DataTable dtData, string FilePath)
{
using (StreamWriter sw = new StreamWriter(FilePath, false))
{
for (int x = 0; x < dtData.Columns.Count; x++)
{
sw.Write(dtData.Columns[x].ColumnName + ",");
}
sw.WriteLine();
foreach (DataRow row in dtData.Rows)
{
for (int n = 0; n < dtData.Columns.Count; n++)
{
sw.Write(row[n].ToString() + ",");
}
sw.WriteLine();
}
sw.Close();
}
} Thanks,
T.Saravanan
Agopi.net, if this helps please login to Mark As Answer. |
Reply | Alert Moderator
|
Agopi.net
Posted on: 6/8/2012 1:32:34 PM
|
Level: Starter | Status: [Member] | Points: 25
|
Hi Saravanan,
Could you please let me know what kind of data to pass here. Can you please send me the full code on this.
Agopi.net, if this helps please login to Mark As Answer. |
Reply | Alert Moderator
|
Agopi.net
Posted on: 6/8/2012 1:37:47 PM
|
Level: Starter | Status: [Member] | Points: 25
|
Hi,
I am struggled and get confusion that what kind of data should pass in these kind of functions. could you please explain your code (please provide the full code)
Agopi.net, if this helps please login to Mark As Answer. |
Reply | Alert Moderator
|
Just replace in Original source like the following...
In which places u used "\t" , just replace as ",\""
Now u can get ur expection..
Regards,
Singaravel M
Agopi.net, if this helps please login to Mark As Answer. |
Reply | Alert Moderator
|
Agopi.net
Posted on: 6/10/2012 1:23:57 PM
|
Level: Starter | Status: [Member] | Points: 25
|
Hi Singravel,
Thanks for your help. I have changed the below line as per your instruction. But I hope this is not a correct method even we got the answer. We need to placed the delimiter after read the values from gridview by cell wise.
sw.WriteLine("\""+ dataGridView1.Rows.Cells[0].Value.ToString() + "\",\"" + dataGridView1.Rows.Cells[1].Value.ToString()+ "\"" );
Also i need explanation on Mr.Saravanan Code.
What kind of data we should pass.
Where we should pass (from any button control)
Agopi.net, if this helps please login to Mark As Answer. |
Reply | Alert Moderator
|