Results 1 to 10 of 10

Thread: [RESOLVED] How to get text from a text file and save it in the application?

  1. #1

    Thread Starter
    Lively Member despotovski01's Avatar
    Join Date
    Apr 2011
    Posts
    100

    Resolved [RESOLVED] How to get text from a text file and save it in the application?

    So, here's the situation.
    I first want my program to get the text from a text file(I know how that's done), but once it gets it, I want to somehow save it that it won't need to get the text again(for example, if you restart the application, it won't need to get the text from the file because the text is already saved). Can you please help me with this?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: How to get text from a text file and save it in the application?


  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to get text from a text file and save it in the application?

    If an application wants to save data, it saves it to a file. You can save it to a different file if you want, e.g. a database (which is a file underneath) or the application config file, but it will still be a file of some sort. You can store data inside the EXE itself as a resource, but that is something that you do at compile time.

    I would guess that your best bet would be to use an application setting. You create it on the Settings page at design time and you can then assign the text from the other file to the property of My.Settings in code. The value of the setting will then be saved automatically at shutdown and reloaded automatically at startup.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Lively Member despotovski01's Avatar
    Join Date
    Apr 2011
    Posts
    100

    Re: How to get text from a text file and save it in the application?

    Quote Originally Posted by jmcilhinney View Post
    If an application wants to save data, it saves it to a file. You can save it to a different file if you want, e.g. a database (which is a file underneath) or the application config file, but it will still be a file of some sort. You can store data inside the EXE itself as a resource, but that is something that you do at compile time.

    I would guess that your best bet would be to use an application setting. You create it on the Settings page at design time and you can then assign the text from the other file to the property of My.Settings in code. The value of the setting will then be saved automatically at shutdown and reloaded automatically at startup.
    I partially get what you are saying, but I don't know how to do it. I have never worked with My.Settings before.

  5. #5

    Thread Starter
    Lively Member despotovski01's Avatar
    Join Date
    Apr 2011
    Posts
    100

    Re: How to get text from a text file and save it in the application?

    Anyone?

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: How to get text from a text file and save it in the application?

    Go into Project|Properties and look at the Settings tab. You can add custom settings in there of various types.

    Once you have added a setting to hold your information, you would access it for either reading or writing with:

    My.Settings.<your setting name here>

    It would act pretty much like a variable that is loaded every time your program starts. If you want to add a different number of strings each time, you can use the Specialized.StringCollection type, which would give you something akin to a List (of String).
    My usual boring signature: Nothing

  7. #7
    Member
    Join Date
    Apr 2010
    Posts
    43

    Re: How to get text from a text file and save it in the application?

    Tutorial here.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to get text from a text file and save it in the application?

    Once you've added the setting to your app, all the code you need is basically:
    vb.net Code:
    1. My.Settings.SomeSetting = IO.File.ReadAllText("file path here")
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Lively Member despotovski01's Avatar
    Join Date
    Apr 2011
    Posts
    100

    Re: How to get text from a text file and save it in the application?

    Quote Originally Posted by jmcilhinney View Post
    Once you've added the setting to your app, all the code you need is basically:
    vb.net Code:
    1. My.Settings.SomeSetting = IO.File.ReadAllText("file path here")
    Quote Originally Posted by HerkyBird
    Tutorial here
    Thanks guys! I will try this and post the results what happened.

  10. #10

    Thread Starter
    Lively Member despotovski01's Avatar
    Join Date
    Apr 2011
    Posts
    100

    Resolved Re: How to get text from a text file and save it in the application?

    Thanks to all! I've solved my problem!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width