954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to save TextBox1.text to Textfile1.txt within the project

Hello all, I just joined the site.

I hope someone can help me with a minor problem, I have been searching both this site and google for the anwser... but keep getting stuck.

A dialog with a textbox is reading a text file within the project like this

Private Sub StandardPharses_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim mystream As System.IO.Stream = System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream("Textfile1.txt")
        Using reader As New IO.StreamReader(mystream)
            ' Read the contents into TextBox
            TextBox1.Text = reader.ReadToEnd
        End Using
    End Sub

That works fine, but how to save the edited text back to the file when I hit Save

Bucher
Newbie Poster
3 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

you want to update the same file? first delete the content and using io.write u can write back and save...

Pgmer
Master Poster
714 posts since Apr 2008
Reputation Points: 54
Solved Threads: 121
 

i believe you can't possibly write back since the file you are using is read-only. It must be embedded into the exe(Check if I am right). You can embed files only before compiling or if you could find a way to manipulate an exe but that will just corrupt the exe or may produce runtime inconsistency, in other words not-poossible. rather store data in .config files

Also System.IO helps writing to files on the disk ur file is probably not stored on disk :) so not io functionality can work

AnkitGuru
Light Poster
32 posts since Jul 2011
Reputation Points: 8
Solved Threads: 5
 
you want to update the same file? first delete the content and using io.write u can write back and save...

Thanks for your reply, can you provide me with an example code? as I have tried something like that with no luck

Bucher
Newbie Poster
3 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

i believe you can't possibly write back since the file you are using is read-only. It must be embedded into the exe(Check if I am right). You can embed files only before compiling or if you could find a way to manipulate an exe but that will just corrupt the exe or may produce runtime inconsistency, in other words not-poossible. rather store data in .config files

Also System.IO helps writing to files on the disk ur file is probably not stored on disk :) so not io functionality can work

Thanks for your reply.. yeah you might be right about the read only.. I will look into useing a .config insted

Bucher
Newbie Poster
3 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: