Results 1 to 2 of 2

Thread: THE SaveFile Class

  1. #1

    Thread Starter
    Addicted Member spyk3's Avatar
    Join Date
    Apr 2009
    Location
    Dothan, AL
    Posts
    218

    THE SaveFile Class

    Today's upload is a simple class I've made to help all of out there who are constantly needing to make saves to the app data folders (aka, where every good windows program saves any user data that is not registry filed).

    The class isn't very complex and, if you're a beginner looking to see some simple class stuff and simple file and folder checks, enjoying breaking it down. Otherwise, just add this class to any project and enjoy free and easy file saving!

    The class does 1 of 2 things when called.
    It either
    A: creates "Path" (not a file or folder) for the current user that is located in the Program Data folder area
    or
    B: creates a Public "Path" at the Program Data Location

    This class helps to ensure you are quickly and easily saving to the same folder "area" as everyone else who writes anything decent for windows.
    It also includes 2 very basic functions "create" & "delete" which, of course, create or delete whatever your current path is (the path created when you called the class).

    Example 1 Code:
    1. Dim bob As New SaveFile("SomeFolder(usuallyAppName)", "SomeFile.txt")
    2. ' Optional para let's u choose whether it includes the current username or if it goes in a public folder
    3. '  then reuse is ez, like ...
    4. SomeReadWriteClass.Save(bob.file.path)

    to see more examples of how it will pull,
    create a new form proj
    add this class
    add a richtextbox
    then add the following code to the form's load event
    Example 2 Code:
    1. Dim bob As New SaveFile("", "SomeFile.txt")
    2.  
    3.         With bob
    4.             rtxTest.AppendText(.adpUserPath)
    5.             rtxTest.AppendText(Environment.NewLine)
    6.             rtxTest.AppendText(Environment.NewLine)
    7.             rtxTest.AppendText(.Folder.Name)
    8.             rtxTest.AppendText(Environment.NewLine)
    9.             rtxTest.AppendText(.Folder.Path)
    10.             rtxTest.AppendText(Environment.NewLine)
    11.             rtxTest.AppendText(.Folder.Exist)
    12.             rtxTest.AppendText(Environment.NewLine)
    13.             rtxTest.AppendText(.File.Name)
    14.             rtxTest.AppendText(Environment.NewLine)
    15.             rtxTest.AppendText(.File.Path)
    16.             rtxTest.AppendText(Environment.NewLine)
    17.             rtxTest.AppendText(.File.Exist)
    18.             rtxTest.AppendText(Environment.NewLine)
    19.             .Folder.Name = .Folder.Name & "\NewSubFolder"
    20.             rtxTest.AppendText(.Folder.Path)
    21.             rtxTest.AppendText(Environment.NewLine)
    22.             bob = New SaveFile(.Folder.Name.Replace("\NewSubFolder", "") & "\NewSubFolder", "Bob.exe")
    23.         End With
    24.         With bob
    25.             rtxTest.AppendText(.Folder.Path)
    26.             rtxTest.AppendText(Environment.NewLine)
    27.             .File.Name = "Bob.dll"
    28.             rtxTest.AppendText(.File.Path)
    29.             rtxTest.AppendText(Environment.NewLine)
    30.         End With

    The preceding will produce something like this:
    C:\ProgramData\UserName

    WindowsApplication1
    C:\ProgramData\UserName\WindowsApplication1
    False
    SomeFile.txt
    C:\ProgramData\UserName\WindowsApplication1\SomeFile.txt
    False
    C:\ProgramData\UserName\WindowsApplication1\NewSubFolder
    C:\ProgramData\UserName\WindowsApplication1\NewSubFolder
    C:\ProgramData\UserName\WindowsApplication1\NewSubFolder\Bob.dll
    The attached zip includes both the simple vb class and a dll you can use to just reference in if preferred. Note: you do not need both, as they are both the same thing.
    Attached Files Attached Files

  2. #2

    Thread Starter
    Addicted Member spyk3's Avatar
    Join Date
    Apr 2009
    Location
    Dothan, AL
    Posts
    218

    Re: THE SaveFile Class

    Oh and don't forget the simple functions like
    vb Code:
    1. MsgBox(bob.Folder.Create())
    2. '  will reutrn true if it create the folder OR if it already exist, false otherwise

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