VB 2008 Project Folder Description...

I have two files in .../bin/Debug folder as shown on the attached image. The original project folder (in this case 'Eghtebas_Mike Ch 9 Problem 3') could be anywhere (in C: drive, on desktop not necessarily in VB2008 defaule folder).

SampleData.txt
ScoreList.txt

Once in a while user may want to reset the data in ScoreList.txt to what is in SampleData.txt.

Q1: What is the best way to do this (for example copy SampleData.txt as SampleData_copy.txt and then delete ScoreList.txt and at last rename SampleData_copy.txt as ScoreList.txt)? What is the code to do this because bin/Debugh could be anywhere as discussed before.

Q2: What is the function of each folder shown on the attached image? I understand this could be a lenghty description; therefore, identifying the major folders will do. Also, any link to read more about the folder structure will be helpful.

Thank you.



 VB2008 Project Folder
LVL 34
Mike EghtebasDatabase and Application DeveloperAsked:
Who is Participating?
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
"Once in a while user may want to reset the data in ScoreList.txt to what is in SampleData.txt."

You could embed SampleData.txt in your exe so it doesn't need to be external.  Then you can simply read it and overwrite the contents of ScoreList.txt.

To add the text file as an embedded resource:
(1) Project --> Add Existing Item.
(2) Change Filter to All Files, browser to your text file, and double click it.
(3) Select the resource in the Solution Explorer Pane (top right by default).
(4) Down below in the Properties Pane, change the Build Action to Embedded Resource.
*Note that when accessing this resource by name it is CaSe-SeNsItIvE so make it match exactly as it appears in your solution explorer listing.

You can use "My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData" to hold your data file.

If the data file doesn't exist at form load you can simply create it using the data from the embedded resource.

Here's where the GetResourceContent() function came from:
http://www.devx.com/vb2themax/Tip/19589

Simple example:
Imports System.IO
Public Class Form1

    Dim DataFile As String = My.Computer.FileSystem.CombinePath(My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData, "ScoreList.txt")

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not My.Computer.FileSystem.FileExists(DataFile) Then
            ResetDataFile()
        End If
    End Sub

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ResetDataFile()

        MessageBox.Show(DataFile)
        Process.Start(DataFile)
    End Sub

    Private Sub ResetDataFile()
        Dim contents As String = GetResourceContent("SampleData.txt")
        My.Computer.FileSystem.WriteAllText(DataFile, contents, False)
    End Sub

    Function GetResourceContent(ByVal filename As String) As String
        ' get the current assembly
        Dim asm As System.Reflection.[Assembly] = _
            System.Reflection.[Assembly].GetExecutingAssembly()
        ' resources are named using a fully qualified name
        Dim strm As System.IO.Stream = asm.GetManifestResourceStream(asm.GetName() _
            .Name + "." + filename)
        ' read the contents of the embedded file
        Dim reader As New System.IO.StreamReader(strm)
        GetResourceContent = reader.ReadToEnd()
        reader.Close()
    End Function

End Class

Open in new window

0
 
Carl TawnSystems and Integration DeveloperCommented:
1) You could do that. You can use Application.StartupPath to give you the folder where your application lives.

2) "bin" contains the binaries from your project, one set from teh Debug build and one from the Release build.
    "obj" contains temporary files used by the compiler while building the project. Again there are versions for Debug and Release.
0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
re:> 1) You could do that.

I need the code. Also, if the project folder in my desktop, running it on your desktop, how would it know its location?

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
1. re:> CaSe-SeNsItIvE

Is this short like FYI (for For Your Information)? Or, it is a name I will be using it in my codes?

2. re:> My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData
Because it is intended to keep it in bin/Debug, is the following path correct?
Using ScoreFile As New StreamReader(My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData & "\bin/Debug\ScoreList.txt")    or perhaps

Using ScoreFile As New StreamReader(path + "\bin\Debug\ScoreList.txt")

3. re:> If the data file doesn't exist at form load you can simply create it using the data from the embedded resource.

In my code, while executing (for exampe):

Using ScoreFile As New StreamReader(path + "\bin/Debug\ScoreList.txt")

If the txt file is not found, what the error trapping needs to be and how can I copy and rename the embeded SampleData.txt to bin\Debug\ScoreList.txt?

Sorry, there are lots of questions here. Please let me know if I need to break them to new questions.

Mike
0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
I guess 3 question is answered by your code at the end of your last post.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
#1 Case Sensitive means that you have to match the case EXACTLY for it to work.  This is one of the few instances in VB.Net where case actually matters.  For example, if the embedded text file appeared as "SomeFile.txt" in Solution Explorer, then you'd have to pass "SomeFile.txt" to GetResourceContent() exactly as it appears.  If you passed "somefile.txt" then the embedded resource would not be found since the case doesn't match.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
#2 The directory isn't easily accessible so I wouldn't bother with forcing a sub-tree structure unless there was a very good reason for it.  If the user needs to access the file then I'd let them pick the location using a SaveFileDialog().

Try this out to see where the folder is:

    Dim DataFile As String = My.Computer.FileSystem.CombinePath(My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData, "ScoreList.txt")

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        MessageBox.Show(DataFile)
    End Sub

If you do want to keep the subfolders then you'd also have to check for the existence of the folders and create them before you go trying to create the file.
0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Hi Idle_Mind,

This wonderful code reproduces sample data from SampleData.txt so the user could continue her/his work. However, after the session ends and the application is closed, all of the new data will be lost because we have not created a physical copy of the working file as bin\Debug\ScoreList.txt.

Also, there is an error as you can see on the attache dimage along with 3 questions for your comment.

Thank you,

Mike
VB2008ProjectFolder-1.png
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Hadn't gotten back to this last issue yet...you figured it all out?
0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
It seems, I need to do some reading to get my arms around the concept. Meanwhile I want to get this small project done using the method discussed (a new question):

http://www.experts-exchange.com/Programming/Languages/.NET/Q_26650472.html

Thank you for the follow-uo.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.