Click here to Skip to main content
15,071,262 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

I have a question relate to a code like this, I want to overwrite textfile which data get from Datagridview {Name, Webtype, Statuse, Website URL, Auto} by i want to select only one column "Website URL" all value to overwrite into textfile.

What I have tried:

I haven't write any code yet being thinking to find this solution if you have any good ideas about it, please share me
Posted
Updated 15-May-21 20:00pm

1 solution

The actual overwrite is easy: The File class[^] alone contains several methods that will do it, never mind the FileStream class[^]:
File.WriteAllBytes(String, Byte[]) Method (System.IO) | Microsoft Docs[^]
File.WriteAllLines Method (System.IO) | Microsoft Docs[^]
File.WriteAllText Method (System.IO) | Microsoft Docs[^]
Are the main ones.

So the problem is collecting the data - and that isn't difficult either, but exactly how to do it will depend on your DGV and how you loaded it with data, plus what you actually want in the file. And we have no idea on either of those.

If you added rows manually, the loop through all rows and combine each of the URL containing cells into an output (StringBuilder, List, whatever floats your boat).

If you used a DataSource, then look to the data you provided DGV with, and use that. We have no idea what you used, and there are far, far too many possibilities for us to give you anything like a precise answer!


So start with what you want in the file, then look at your data itself. We can;t do that for you!
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900