Results 1 to 20 of 20

Thread: [RESOLVED] Anyway of adding a file to my program and saving it inside of it

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2014
    Location
    Michigan, USA
    Posts
    19

    Resolved [RESOLVED] Anyway of adding a file to my program and saving it inside of it

    I have a simple program, i'll try to make this short and sweet, and upon drag/drop of a file into the form it saves to location and name of the file.

    How would i go about adding the file to the program and storing it?

    So it would add to the complied program and save the data of that file inside so that upon startup of the program, that saved file wouldn't be located where it was dragged and dropped from, it would be in the program.
    (trying to stress what i need, sorry for being excessive)
    Last edited by Mr_Cam; Sep 21st, 2014 at 11:25 PM. Reason: potential answerers' convenience

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

    Re: Anyway of adding a file to my program and saving it inside of it

    Why would you want such a thing? It's not usually done and for very good reason.
    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

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2014
    Location
    Michigan, USA
    Posts
    19

    Re: Anyway of adding a file to my program and saving it inside of it

    So the file(s) can move with the program. The program has a password, after it is entered i can view my files inside it in the program, even if I'm not on the same computer.

    I have been able to do this without adding them to the program. But once you move the program to another location other than that specific computer, It no longer can find the files (obviously).
    So i was wondering how i could do this.
    It seems like a very simple concept, yet i haven't found anything of the sorts.

    Or even if i had a textfile in the program, and it would save the text inside each file, and it would (save settings and such) on close. SO upon reopening it would have the contents that it could 'reassemble' if i needed them.
    Last edited by Mr_Cam; Sep 22nd, 2014 at 01:29 PM.

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Anyway of adding a file to my program and saving it inside of it

    When would you add the file? at design time, or at run time, by the user?


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    Lively Member
    Join Date
    Aug 2014
    Posts
    87

    Re: Anyway of adding a file to my program and saving it inside of it

    I don't fully understand what you want to do, but I have a idea of what you could do... A concept*:

    On form load do the following code:

    Code:
    If Not IO.Directory.Exists(Application.StartupPath + "\addedapps\") Then
                IO.Directory.CreateDirectory(Application.StartupPath + "\addedapps\")
            End If
    ^^ this will check if a folder where your app was started up exists, if not create it.

    On the drag/drop event, you can use IO.File.Move() or IO.File.Copy() to move the file to Application.StartupPath + "\addedapps".

    Then, after all folder checking call a sub to loop through all files and add to a listbox. Then, loop through listbox items and for each one (whatever code to add it in the app from drag and drop) and where.

  6. #6
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    Re: Anyway of adding a file to my program and saving it inside of it

    Checking a directory exists is not needed VisualB, If you read MSDN documentation for IO.Directory.CreateDirectory

    Any and all directories specified in path are created, unless they already exist or unless some part of path is invalid. If the directory already exists, this method does not create a new directory
    My Github - 1d3nt

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Sep 2014
    Location
    Michigan, USA
    Posts
    19

    Re: Anyway of adding a file to my program and saving it inside of it

    When the user drags and drops an item (file) into a control.

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

    Re: Anyway of adding a file to my program and saving it inside of it

    Quote Originally Posted by Mr_Cam View Post
    When the user drags and drops an item (file) into a control.
    So you think that it's a simple matter of the compiled EXE file rewriting itself without having to be recompiled?
    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
    Junior Member
    Join Date
    Sep 2014
    Location
    Michigan, USA
    Posts
    19

    Re: Anyway of adding a file to my program and saving it inside of it

    No, just having the program saving a variable and re-loading that variables previous value (without having to access a local file).

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

    Re: Anyway of adding a file to my program and saving it inside of it

    Quote Originally Posted by Mr_Cam View Post
    No, just having the program saving a variable and re-loading that variables previous value (without having to access a local file).
    But variables exist in memory. When the application exits it is removed from memory and all variables cease to exist. In order to persist data between sessions on the same machine even you need to store the data in a file of some sort. I think that you're under some serious misconceptions about how computer programs work.
    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

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Sep 2014
    Location
    Michigan, USA
    Posts
    19

    Re: Anyway of adding a file to my program and saving it inside of it

    Actually I've found a way in which i could do this. And no, I'm not 'under some serious misconceptions about how a computer program works'.
    I went into program (project) properties >> Settings and added 'variables' that i could set and then later retrieve when i run the program again.

    Using this to set the variable(s) that I added in the program settings<


    For example if i added a string variable 'file1' in the settings:
    Code:
    <textbox1.textchanged>
    My.Settings.file1 = textbox1.text
    My.Settings.Save()
    set the setting 'file1' to the path to the file or the file.readalltext(file1) to get the contents required to 'recreate' the file.

    Note:
    -It does not need to be a textbox or the text property
    -It could be a picturebox.imagelocation or even me.location (if file1 was set to a point variable and not a string)


    Then on the onload() of my program i had wrote:
    Code:
    If My.Settings.file1 <> "" then
          textbox1.text = My.Settings.file1
    End If
    sets textbox control's text equal to the value of the file1 setting.


    This all would:
    1. Initialize a program setting that i could use to save variable for my program
    2. Give the setting a value
    3. Retrieve the setting's value and set a control property to it's value


    #I will continue to perfect this on my own#
    #Marking as resolved to save the forum peeps from more grief#
    #Thanks for everyone's input!#

    ~Cam~
    Last edited by Mr_Cam; Sep 23rd, 2014 at 02:50 AM. Reason: stufffff

  12. #12
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,657

    Re: Anyway of adding a file to my program and saving it inside of it

    Erm, thats not going to work! Its seems you do have some misconceptions.

    What your asking is not possible, Variables are in memory FULL STOP. As soon as your program stops running you lose your variable values unless you save them to a file.

    Those Settings files,

    Application Settings are Read Only

    The User Settings the ones which you can write to, the ones you seem to be mistaking for Variables, they are stored in a separate file normally under -

    %USERPROFILE%\Application Data\<Company Name>\<appdomainname>_<eid>_<hash>\<verison>\user.config.

    If you are trying to store stuff in the settings and are under the impression that these will automatically move with your program then you are mistaken, they are not part of the program, they are in a separate file!!!

    Variables are in run-time Memory only, setting you want to persist you have to save to a file.

    What you should be looking at is a Cloud solution.

    This way you could move your program around or login from different places and access your files from where ever without having to copy the files to each PC as the files live in the Cloud.
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  13. #13
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,657

    Re: Anyway of adding a file to my program and saving it inside of it

    Double Post
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



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

    Re: Anyway of adding a file to my program and saving it inside of it

    Quote Originally Posted by Mr_Cam View Post
    Actually I've found a way in which i could do this. And no, I'm not 'under some serious misconceptions about how a computer program works'.
    I went into program (project) properties >> Settings and added 'variables' that i could set and then later retrieve when i run the program again.

    Using this to set the variable(s) that I added in the program settings<


    For example if i added a string variable 'file1' in the settings:
    Code:
    <textbox1.textchanged>
    My.Settings.file1 = textbox1.text
    My.Settings.Save()
    set the setting 'file1' to the path to the file or the file.readalltext(file1) to get the contents required to 'recreate' the file.

    Note:
    -It does not need to be a textbox or the text property
    -It could be a picturebox.imagelocation or even me.location (if file1 was set to a point variable and not a string)


    Then on the onload() of my program i had wrote:
    Code:
    If My.Settings.file1 <> "" then
          textbox1.text = My.Settings.file1
    End If
    sets textbox control's text equal to the value of the file1 setting.


    This all would:
    1. Initialize a program setting that i could use to save variable for my program
    2. Give the setting a value
    3. Retrieve the setting's value and set a control property to it's value


    #I will continue to perfect this on my own#
    #Marking as resolved to save the forum peeps from more grief#
    #Thanks for everyone's input!#

    ~Cam~
    As NeedSomeAnswers has explained, that doesn't actually do what you think it does. It is certainly a solution to persisting simple data between sessions on the same machine but, as explained, it's data stored in an external file that is not going to automatically follow your EXE to another machine.

    If you are going to use that as a solution for a single machine though, you don't actually need any code at all in most cases. If you select a control in the designer and open the Properties window, you can use the (ApplicationSettings) node to bind to new or existing settings for most properties. Binding means that any change to one affects the other, so the fact that settings get automatically loaded at startup means that your TextBox gets automatically populated. Any input to the TextBox is automatically pushed to the setting as well. Settings are automatically saved at shutdown, so there's no need for any code at all.
    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

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Sep 2014
    Location
    Michigan, USA
    Posts
    19

    Re: Anyway of adding a file to my program and saving it inside of it

    Not using a cloud
    Im settling with the **** way of saving settings
    All other ways aren't doing what I want then to

    I'm done.


    ~Cam~
    Last edited by Mr_Cam; Sep 23rd, 2014 at 09:03 AM.

  16. #16

    Thread Starter
    Junior Member
    Join Date
    Sep 2014
    Location
    Michigan, USA
    Posts
    19

    Re: Anyway of adding a file to my program and saving it inside of it

    Ik they aren't variables. But they act in the exact way. So how about you drop the ******* subject. You have some misconceptions too.

  17. #17
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,657

    Re: [RESOLVED] Anyway of adding a file to my program and saving it inside of it

    Cam,

    no need to get angry, the post from myself or JMC where not meant to insult you in any way don't take it personally.

    If the Settings File gives you what you want then great.

    Settings are not the same as Variables and we wanted you to understand the difference.

    At first it seemed you wanted the setting to move with you when you moved your program to another computer, in this case the setting approach will not work.

    For different sessions on the same computer (which it does now sound like you are doing) then it will work.

    That i think resulted in the confusion
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  18. #18

    Thread Starter
    Junior Member
    Join Date
    Sep 2014
    Location
    Michigan, USA
    Posts
    19

    Re: [RESOLVED] Anyway of adding a file to my program and saving it inside of it

    I think to complete my needs i will have to have 2 programs. One that is this one that is being discussed, and another that checks for local files saved and the location of the actual program and when it is moved the secondary prgram would move the file too. But then it still wouldn't work if i did have it go from one computer to another.

    NeedSomeAnswers,
    i understand what you said and what you were saying and why you did so.
    I am only frustrated at the approach of the situation and how it differs from my initial thought. I am not directly mad at anyone.
    My apologies.

    Prehaps you could take a look at my first thread.
    here
    I know it is possible to fix the problem in that one.
    But for now have lost hope, seeing as the first reply is yet to be posted.



    ~Cam~
    Last edited by Mr_Cam; Sep 23rd, 2014 at 07:18 PM. Reason: exta

  19. #19
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [RESOLVED] Anyway of adding a file to my program and saving it inside of it

    Legit programs simply don't work that way. Why? Because that's how viruses do work. You're not going to find a good way to make something so completely self-contained the way you want.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  20. #20

    Thread Starter
    Junior Member
    Join Date
    Sep 2014
    Location
    Michigan, USA
    Posts
    19

    Re: [RESOLVED] Anyway of adding a file to my program and saving it inside of it

    Thanks, but as you probably didn't see, this is marked as [Resolved] and requires no more input.


    ~Cam~

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