Nuguns

Hello everyone. I am currently working on a program that reads an access file and the creattes a report based on the contents of the file. Nothing too difficult. I have the program working, but my problem is i need to burn this program to a disc, and the code only allows for the file to be located at a specific path. Here is a small part of what what I have now:

Code Snippet

Dim connectStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=D:\My Documents\EzWatt Customer Billing Program\EzWattCustomerDatabase.mdb;"


The problem is that when the file is burnt to a cd and then used on any other computer the file is not at the specified path, and an error is returned. I am looking for a way to include the file in the build files somehow. I know that this cant be that difficult to do, however after searching menus and online guides for days now i have not been able to find out how to do this. Any help would be greatly appreciated



Re: Visual Basic Express Edition Running a program off a cd

Tall Dude

See the last part of my answer at:

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1414906&SiteID=1

It may be useful.






Re: Visual Basic Express Edition Running a program off a cd

Nuguns

Thank you for your prompt reply, but that wasn't quite what i was looking for. The program has to be able to run no matter what the drive configuration is. So even if i use the copy file method, it still wont work is the drive isn't right. I know that i could probably count on the C: drive being the main windows drive the majority of the time, but not always. Also i realize that i could jsut copy the file to C:\ but this isn't preffered because it really should be put with the temp files. anyways, tall dude, you last post wasn't quite what i was looking for. if anyone else has any ideas they would be greatly appreciated.




Re: Visual Basic Express Edition Running a program off a cd

Tall Dude

Did you notice this part of my long running notes (In the link.)

' NOTICE !!!!!

' That to get around the 'where is my file ' problem,

' that the file is written AND read using no drive letter

' or pathway. This causes Visual Basic to write the file

' whereever your program is running from and try to

' read it from whereever your program is running from

What this means in a nutshell is that someone does not run

your program off of a CD. They install it off of a CD.

If by chance the program gets installed on drive D:, big deal.

If your program writes a file with no drive and no path, and trys

to read it the same way, with no drive and no path; the file

will be found.






Re: Visual Basic Express Edition Running a program off a cd

Nuguns

I did see that part, unfortunately, i don't want the user to have to install the program. It is supposed to be a mobile program with no installation required. And without an installation the program attempts to write the file to the cd drive which is of course impossible. Do you know of any other way




Re: Visual Basic Express Edition Running a program off a cd

Tall Dude

I have used the following to find what should be a writeable drive:

Dim drive As String = System.IO.Path.GetPathRoot(My.Computer.FileSystem.SpecialDirectories.MyDocuments)

and then created folders under some of the specialdirectories, on that drive, to put

a file to a known position on an unknown target PC.






Re: Visual Basic Express Edition Running a program off a cd

Nuguns

That last post helped a lot, because i now know how to find the correct drive, however i am having trouble copying the file from my resources.


Code Snippet

Dim drive As String = System.IO.Path.GetPathRoot(My.Computer.FileSystem.SpecialDirectories.Temp)



My.Computer.FileSystem.CopyFile(My.Resources.EzWattCustomerDatabase, drive)


I now however get an error :

Error 7 Value of type '1-dimensional array of Byte' cannot be converted to 'String'. C:\My Documents\Visual Studio 2005\Projects\EzWattBillingProgram\EzWattBillingProgram\RecordSearch.vb 25 41 EzWattBillingProgram

I've searched for this error on Google, but i haven been able to find any good information. is the .mdb database file supposed to be a string





Re: Visual Basic Express Edition Running a program off a cd

Tall Dude

You cannot do a file copy directly on an embedded resource

because it does not yet exist as a discreate separate file.

Do this instead:

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button1.Click

' Where file 'db1.mdb' is an embedded resouce file

Dim drive As String = _

System.IO.Path.GetPathRoot(My.Computer.FileSystem.SpecialDirectories.MyDocuments)

If Not System.IO.Directory.Exists(drive & "MyNewCoolFolder") Then

System.IO.Directory.CreateDirectory(drive & "MyNewCoolFolder")

End If

System.IO.File.WriteAllBytes _

(drive & "MyNewCoolFolder" & "\workcopy.mdb", My.Resources.db1)

End Sub

End Class