Click here to Skip to main content
15,867,957 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am using Visual c# 2010 express
I want to be able to add a file in a Windows Forms Apllication or WPF browzer application
how do I add a text file to the project and then access its contents and change them
I want to use this to make a rating system in my website
when someone rates the rate should be added to the text file...

the text file should be integrated in the project itself
Posted
Updated 26-Feb-11 11:13am
v2

Create a text file.
Just add it to your project by right clicking on your project and adding "add files".

Modify the file as and when you require via code.

Finally, make sure it goes out in the setup.
 
Share this answer
 
Comments
CS2011 27-Feb-11 2:52am    
i think it's a better approach in some case...it's gives you freedom to edit the files with ease...my 5
Make it a resource. Add both new resource file and existing text file to the project, in the resource editor (where resource types are listed) use "Add existing file". You don't have to read the content of the resource. Pay attention, a C# code will be auto-generated under the resource node. Open this code; you will find a static string property (usually under the name close the the name of your text file).

In this way, the text file is integrated to the project itself, but not copied to the output but embedded in the executable.

If you want the file to be copied, though, you can simply add the text file to the project, go to the node's properties and specify its build behavior ("Copy always", for example). In this case, you will need to access the file via regular IO.

I would highly recommend to use embedding in the resource, not using IO.

—SA
 
Share this answer
 
Comments
john1990_1 26-Feb-11 18:19pm    
this one works thanks
but what if I wanted to write or edit the txt file
it says its read only!!

I mean I use
WpfBrowserApplication1.Properties.Resources.TextFile1
but it is read only
Sergey Alexandrovich Kryukov 26-Feb-11 20:31pm    
No, you cannot edit data in resource, of course. If you want, you can copy the string and edit it (text box or whatever) and save it elsewhere, right? Or, you can use second method. Anyway, if your explain the goal of it (please, use "Improve question" don't post as Answer), maybe I could advise something better.
--SA

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