DKB

I am having a hard time creating a path to my images folder whether it be an absolute or a relative path. I continue to get this error can somebody please help this is time sensitive. Thanks

DKB

System.IO.FileNotFoundException was unhandled
Message="\images\die0.png"
Source="System.Drawing"

StackTrace:
at System.Drawing.Image.FromFile(String filename, Boolean useEmbeddedColorManagement)
at System.Drawing.Image.FromFile(String filename)
at My_Craps_Game.Form1.DisplayDie(PictureBox picDie, Int32 Face) in C:\Documents and Settings\David\My Documents\Visual Studio 2005\Projects\My Craps Game\My Craps Game\Form1.vb:line 99
at My_Craps_Game.Form1.rollDice() in C:\Documents and Settings\David\My Documents\Visual Studio 2005\Projects\My Craps Game\My Craps Game\Form1.vb:line 132
at My_Craps_Game.Form1.playButton1_Click(Object sender, EventArgs e) in C:\Documents and Settings\David\My Documents\Visual Studio 2005\Projects\My Craps Game\My Craps Game\Form1.vb:line 48
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at My_Craps_Game.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()



Re: Visual Basic Express Edition Path in VS 2005

ahmedilyas

can you show us the code you are using you should also use a try catch block around code that would throw exceptions so you can handle it. As well as this the exception is that it cannot find the file you have requested




Re: Visual Basic Express Edition Path in VS 2005

spotty

As we cant see you code I'll show you something that may help.

In my project I have created a folder called data and in it I have put a file called test.txt

        Dim s As String = IO.Path.Combine(Application.StartupPath, "Data\test.txt")
        Dim strcontent As String = My.Computer.FileSystem.ReadAllText(s)

The following two lines will provide a path to this file as it is relative to the location of the .EXE and read its contents.

 

But if this doesnt help you definately need to show the code and describe what you have done in very clear detail so we can try and help you.

 





Re: Visual Basic Express Edition Path in VS 2005

DKB

 

Here it is

Const FILE_PREFIX As String = "C:\ProjectCrapsGame\die1\die"

Const FILE_SUFFIX As String = ".png"

 

'display die image

Sub DisplayDie(ByVal picDie As PictureBox, _

ByVal Face As Integer)

'assign die image to picture box

picDie.Image = Image.FromFile(FILE_PREFIX & Face & FILE_SUFFIX)

picDie.Image = Image.FromFile(FILE_PREFIX & Face & FILE_SUFFIX)

End Sub

 

 I would like to be able to use a relative path some thing along the line like (~\images\folder\etc) no c:\ ... involved so that I may zip a copy and send off email if I choose I think everyone gets the idea. By the way I don't remember in detail what I wrote earlier but I am able to reference the images but they are in a absolute path my meaning is c:\folder\subfolder\file I wonder if there is a option in VS 2005 that allows for either type.

 

 

 





Re: Visual Basic Express Edition Path in VS 2005

spotty

In my project I have created a folder called data and in it I have put a the image files die1.png -> die6.png

I then have written a function to return the string using the application.startuppath and the io.path.combine method as previously stated.

This returns and displays the filename - all you have to do is apply this to your code.


Public Class Form1
Const FILE_SUFFIX As String = ".png"


Function ReturnPathNameForDie(ByVal Face As Integer) As String
Return IO.Path.Combine(Application.StartupPath, data\Die" & Face.ToString & FILE_SUFFIX)
End Function


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox(ReturnPathNameForDie(1))
End Sub

End Class





Re: Visual Basic Express Edition Path in VS 2005

DKB

I found my answer see I was able to access my folder but not from within my project only from the c:\what ever path\ and that caused me to panic in a administrators point of view. What I did was to make a copy of the project and then publish it and what I found was that VS2005 bought in all the necessary files. Cool ha! Thanks everyone for the help and step it up a notch CIAO.

DKB





Re: Visual Basic Express Edition Path in VS 2005

DKB

 

I think I am turning this in to a biography if anyone knows how to have images as a resource in vs 2005 please contact me   I have a few questions. And yes I thought that I had problem solved but much to my dimise I was wrong. I first Had to figure out what was going on in the code and know that it that is squared away I have this other issue, it has to do with the application finding the files it seems to look only to the root directory and path.





Re: Visual Basic Express Edition Path in VS 2005

DKB

Spotty I tried the code and it did not seem to want to work.That was using the same project I going to create a new project using your code and see if that works. Are you able to explain the logic behind the code so as might be able to place in the proper location.

DKB





Re: Visual Basic Express Edition Path in VS 2005

spotty

OK Very simple.

Go to the Project in Solution Explorer

Add -> New Folder -> Call it data

Project -> Add Existing Item -> select a file.

Ensure that the file is in the folder. If its not you should be able to drag and drop it in the folder. In my case here its a text file called boot.bcd

Right click the file and ensure that the "Copy to Output" property is set to copy if newer or copy always

Use the following code.

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s As String = IO.Path.Combine(Application.StartupPath, "data\boot.bcd")
Dim content = My.Computer.FileSystem.ReadAllText(s)
MsgBox(content)

End Sub
End Class

This code will use the IO.Path.Combine method to create a path in a sub folder and will then use this path to read the contents of the file and display it.

The folder is a sub folder of the folder containing the executable.





Re: Visual Basic Express Edition Path in VS 2005

DKB

What if the files are graphic files will it still be read, I have six files that have to show in picture boxes, four of them to be exact. So my question is what are the details, am I to assume that the first line below is a relative path and I do not need to show a drive letter, secondly the next line has ReadAllText(s) can this read all file types and also will it read multiple files in the folder and last what is the MsgBox(content) I can guess that it is used for readng text in a message box but I need to be sure I had a message box with text in it that was not showing when published but showed in design time. Oh yes I want ot thank you for your help as well and one other thing happy holidays, I my self celebrate Christmas.

Dim s As String = IO.Path.Combine(Application.StartupPath, "data\boot.bcd")

Dim content = My.Computer.FileSystem.ReadAllText(s)

MsgBox(content)





Re: Visual Basic Express Edition Path in VS 2005

spotty

The variable is a string containing the path to a file - how you use it is up to you.   If your using it to load a picturebox as long as you files are in the directory and the path is correct this will work if you use the appropriate method.     Picturebox control .FromFile  would probably be the one.

The example simply uses a textfile as it is very simple and we can verify it has read the contents with a simple message box.  But the concept is of a file in a sub folder and it being relative to the location of the EXE.

If you use this general concept - debug the program and look at the path and you can determine if it is correct.