Solved

VB 2008 Project Folder Description...

Posted on 2010-11-29
10
653 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:Mike Eghtebas
  • 5
  • 4
10 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
Comment Utility
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
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
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
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
"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
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
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
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
I guess 3 question is answered by your code at the end of your last post.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
#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
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
#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
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
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
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
Hadn't gotten back to this last issue yet...you figured it all out?
0
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
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

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now