[.net] placing images in bin folder: what is the default folder of the application.

This topic is 4872 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi, I have created an image processing application in c# but the problem is that the image that i am displaying as a default image in the application window requires me to give full path of the of the folder where it is placed. So i placed the image in bin folder of the application so that it can be accessed irrespective of the computer i m running my application. but it is not working as well. Is there any way i can solve this problem. Please help me. Thanx a lot, bye.

Share on other sites
use the path "ImageName.bmp" or whatever extension. That should grab it from the default place. You are compiling it and running it from the IDE right? If so, that should work. If you are running it out of the debug or release folder then you need to put the image in either of those folders.

Are you sure your image processing is correct? You might have an error and that might not be showing it.

Share on other sites
Actually my application loads to types of files. first it loads .jpg files and secondly another file whose format is defined by me. Initially the default .jpg file loads correctly but when i load my own defined file which is not an image file and is used for some other purpose, the default .jpg file starts giving an exception. but when i change my application by giving the absolute path of the .jpg file this problem does not occur. I think that when i load my other file the default folder changes from the bin folder to the folder in which that other file is placed and hence an exception is raised. But i dont know how to solve this problem.

Thanx again

Share on other sites
SetCurrentDirectory(LPCTSTR lpPathName);
and DWORD GetCurrentDirectory(DWORD nBufferLength,LPTSTR lpBuffer);

http://msdn.microsoft.com/library/en-us/fileio/base/getcurrentdirectory.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/setcurrentdirectory.asp

Share on other sites
First, always use full paths. This way you never lose track of a file. Never assume a current directory!

Second, the path of the application's executable can easily be retrieved by using: System.Windows.Forms.Application.ExecutablePath

Third: always use the methods of the System.IO.Path class to manipulate paths: Combine, ChangeExtention, GetFileNameWithoutExtention etc.

Cheers

Share on other sites
Use Application.StartupPath. This is the path your exe is in, so it will always be accurate. The function below will take something like "ImageFile.bmp" and turn it into the full path (like "C:\Projects\MyProject\bin\Debug\ImageFile.bmp").

public String GetFullFilePath(String FileName){   return( System.IO.Path.Combine(Application.StartupPath, FileName) );}

Share on other sites
Quote:
 Original post by DaWandererUse Application.StartupPath. This is the path your exe is in, so it will always be accurate. The function below will take something like "ImageFile.bmp" and turn it into the full path (like "C:\Projects\MyProject\bin\Debug\ImageFile.bmp").*** Source Snippet Removed ***

Be careful if you're using this when you call programs from other programs. For instance, if you call program B in directory C:\D2 from program A in directory C:\D1, StartupPath will report "C:\D1" when called from inside program B.

Share on other sites
I haven't tested this thoroughly, but I'm guessing if you set up a new AppDomain with the correct path ("C:\D2" in this case), then Application.StartupPath will report the correct path. Were you referring to creating a new Process and executing program B that way?

Share on other sites
Quote:
 Original post by ernowFirst, always use full paths. This way you never lose track of a file. Never assume a current directory!Cheers

Unless you set it yourself using Environment.CurrentDirectory. It also might help your understanding of this problem to examine this variable near where you are having problems.

• 10
• 19
• 14
• 19
• 15