What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 654 |  Welcome, Guest!   Register  Login
 Home > Forums > C# > Datagridview to notepad Exported textfile need the delimited value ...
Agopi.net

Datagridview to notepad Exported textfile need the delimited value

Replies: 5 | Posted by: Agopi.net on 6/4/2012 | Category: C# Forums | Views: 1487 | Status: [Member] | Points: 10  


Hi,

I want to export the data to notepad (.txt file). I got the code for export the datagridview to notepad. But i need to the exported .txt file as below method (, " ) delimited.

"1","Inthiyaaz","300000"
"2","Imroz","13000"
"3","Afroz Basha","25000"

Below is the link for Export the gridview to .txt file.

http://www.dotnetfunda.com/articles/article393-exporting-data-to-txt-file-using-csharp.aspx

can anybody let me know this details.

By
Gopi A


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

 Replies

T.Saravanan
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
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
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 

Sakthi.Singaravel
Sakthi.Singaravel  
Posted on: 6/8/2012 11:21:30 PM
Level: Silver | Status: [Member] | Points: 25

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
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 

Reply - Please login to reply


Click here to login & reply

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/21/2013 6:36:32 PM