473,654 Members | 2,990 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to set a proper path of a image file? Windows App - C#

23 New Member
Dear Experts,

My project involves developing a Windows Application where i need to load a picture and i used the following code,

Bitmap myBitmap3 = new Bitmap(@"C:\App \images\logo.bm p");

however, this is not convenient as if i try to use the same project folder in another pc, it doesn't work. so i tried the following,

Bitmap myBitmap3 = new Bitmap(@"\image s\logo.bmp");

however, it doesn't work either,

Can you help me?
Mar 11 '08 #1
8 5646
dip_developer
648 Recognized Expert Contributor
Dear Experts,

My project involves developing a Windows Application where i need to load a picture and i used the following code,

Bitmap myBitmap3 = new Bitmap(@"C:\App \images\logo.bm p");

however, this is not convenient as if i try to use the same project folder in another pc, it doesn't work. so i tried the following,

Bitmap myBitmap3 = new Bitmap(@"\image s\logo.bmp");

however, it doesn't work either,

Can you help me?
create a folder in your solution....sav e the image in that folder.......sa ve the image path in your database.....in my opinion this approach is easy
Mar 11 '08 #2
Anuhas
23 New Member
create a folder in your solution....sav e the image in that folder.......sa ve the image path in your database.....in my opinion this approach is easy

i am not using any database..
is there any other way?
Mar 11 '08 #3
dip_developer
648 Recognized Expert Contributor
i am not using any database..
is there any other way?
then clearly state your problem......wh ere to load your picture......?? ?
Mar 11 '08 #4
spacemanafrica
6 New Member
Dear Experts,

My project involves developing a Windows Application where i need to load a picture and i used the following code,

Bitmap myBitmap3 = new Bitmap(@"C:\App \images\logo.bm p");

however, this is not convenient as if i try to use the same project folder in another pc, it doesn't work. so i tried the following,

Bitmap myBitmap3 = new Bitmap(@"\image s\logo.bmp");

however, it doesn't work either,

Can you help me?
You can get the path to the application like this:

Expand|Select|Wrap|Line Numbers
  1.   System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
  2.   string exedir = asm.Location.Substring(0, asm.Location.LastIndexOf('\\') + 1);
  3.  
then...

Expand|Select|Wrap|Line Numbers
  1. Bitmap myBitmap3 = new Bitmap(@exedir + "images\logo.bmp");
  2.  
Mar 11 '08 #5
Anuhas
23 New Member
You can get the path to the application like this:

Expand|Select|Wrap|Line Numbers
  1.   System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
  2.   string exedir = asm.Location.Substring(0, asm.Location.LastIndexOf('\\') + 1);
  3.  
then...

Expand|Select|Wrap|Line Numbers
  1. Bitmap myBitmap3 = new Bitmap(@exedir + "images\logo.bmp");
  2.  
thanks for your reply,
i tried ur code,
but when i executed the variable asm.location gets assigned with the path of the .exe file in the debug\bin folder, not to Windows App folder..
how to correct this?
Mar 11 '08 #6
Anuhas
23 New Member
then clearly state your problem......wh ere to load your picture......?? ?
Dear Experts,

for my project, i am using an image which i inserted into the project folder and i am using that image as the background of the project. also when i click a button i am changing the background to another image which is a requirement of my project. i was able to do that. but the problem is the image path. i tested it with the absolute path. now i need to set a proper path so that i can use the same project to upgrade in another pc. reply.
Mar 11 '08 #7
Anuhas
23 New Member
Dear Experts,

for my project, i am using an image which i inserted into the
project folder and i am using that image as the background of the project.

also when i click a button i am changing the background to
another image which is a requirement of my project. i was able to do that. but the problem is the image path.

i tested it with the absolute path. now i need to set a proper path
so that i can use the same project to upgrade in another pc. reply.

this is the code i tested first,

Bitmap myBitmap3 = new Bitmap(@"C:\App \images\logo.bm p");

however, this is not convenient as if i try to use the same project folder in another pc, it doesn't work. so i tried the following,

Bitmap myBitmap3 = new Bitmap(@"\image s\logo.bmp");

however, it doesn't work either,

Can you help me?
Mar 11 '08 #8
Plater
7,872 Recognized Expert Expert
I have merged these two threads. Please refrain from double posting.
Mar 11 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
10259
by: Mark | last post by:
Hello all - I'm at wits end with trying to figure out why I'm having this problem since I followed the research, that I've dug up, to a "T". I'm trying to display a JPEG image from a path directory within a Crystal Report. I created a typed dataset that is not bound to the database called dsLogo and created one field within it that has a base64binary type for the image. Once I've incorporated the dataset into the report and dropped the...
3
7953
by: David Thielen | last post by:
Hi; I created a virtual directory in IIS 6.0 and my asp.net app runs fine. But when it tries to write a file I get: Access to the path is denied. - C:\Inetpub\wwwroot\RunReportASP\images C:\Inetpub\wwwroot\RunReportASP is the directory of my virtual directory for my app. In it's properties I did check "Write" as a permission. What else do I need to do?
4
1874
by: John Smith | last post by:
Hello, I'm not sure if these are the appropriate forums for my question since it is closer to about Visual Studio 2005 than it is about .NET framework. So please pardon me and direct me to a different forum if I made a mistake. In any case, thank you for spending the time to read this loooong case and/or for your input. With that said, here's the background of the situation:
11
26594
by: cybervigilante | last post by:
I can't seem to change the include path on my local winmachine no matter what I do. It comes up as includ_path .;C:\php5\pear in phpinfo() but there is no such file. I installed the WAMP package and PEAR is in c:\wamp\php\pear I modified php.ini in the c:\wamp\php directory to reflect the actual path, but even stopping and restarting my server shows the c: \php5\pear path. I can't change it no matter what I do I also tried the...
0
8375
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8815
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8482
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7306
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6161
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5622
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2714
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.