Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB 2008 Project Folder Description...

Posted on 2010-11-29
10
Medium Priority
?
680 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34237026
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 34

Author Comment

by:Mike Eghtebas
ID: 34239894
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 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 34241018
"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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 34242367
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 34

Author Comment

by:Mike Eghtebas
ID: 34242398
I guess 3 question is answered by your code at the end of your last post.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 34242469
#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 86

Expert Comment

by:Mike Tomlinson
ID: 34242518
#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 34

Author Comment

by:Mike Eghtebas
ID: 34243075
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 86

Expert Comment

by:Mike Tomlinson
ID: 34249449
Hadn't gotten back to this last issue yet...you figured it all out?
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 34249785
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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

610 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