Click here to Skip to main content
15,881,588 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
Hello everyone,

I am new in windows application and I have created one windows application. In this I want to show images from img folder which is in my project. Now how can I get the images from img folder? I tried with "Application.ExecutablePath", but it is taking path of bin\Debug directory. I put my img folder in bin\Debug folder but when I create a setup project and install it in my computer its not working.

Please tell me how can I take the path of the img folder in windows application using C#?

Thanks & Regards,
Yogesh
Posted

Here is my detailed answer to a very similar question: how to get image in picturebox from existing Solution explorer Folder in windows application[^].

—SA
 
Share this answer
 
u use this line
C#
string path =System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)
to get application path
& in the start of application check if your image folder is not exists create it
if (!Directory.Exists(path + @"\Images"))
{
Directory.CreateDirectory(path+ @"\Images");
}

so when you creat u setup project no problem
every time u open your solution it check for folder path
 
Share this answer
 
v2
Comments
Dalek Dave 14-Sep-11 3:22am    
Good Call.
VB
Public Function App_Path() As String
     Return System.AppDomain.CurrentDomain.BaseDirectory()
 End Function
 
Share this answer
 
 
Share this answer
 
Yogesh,

When you create your setup project, consider placing the image folder someplace that is 'known', such as c:\ProgramData\YogeshApp\img\ (for Vista and Windows 7). Then you can hard code the path.

The code below will take you to your 'known' folder on XP/Vista/7. Use the same notation for installations.

string imagesFolder = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\YogeshApp\\img\\";


Hogan
 
Share this answer
 
In code behind file write the following code

string filepath=AppDomain.CurrentDomain.BaseDirectory+"\images";


and use filepath variable at the place where you want access images folder
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900