473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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

23
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.bmp");

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(@"\images\logo.bmp");

however, it doesn't work either,

Can you help me?
Mar 11 '08 #1
8 5637
dip_developer
648 Expert 512MB
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.bmp");

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(@"\images\logo.bmp");

however, it doesn't work either,

Can you help me?
create a folder in your solution....save the image in that folder.......save the image path in your database.....in my opinion this approach is easy
Mar 11 '08 #2
Anuhas
23
create a folder in your solution....save the image in that folder.......save 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 Expert 512MB
i am not using any database..
is there any other way?
then clearly state your problem......where to load your picture......???
Mar 11 '08 #4
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.bmp");

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(@"\images\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
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
then clearly state your problem......where 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
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.bmp");

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(@"\images\logo.bmp");

however, it doesn't work either,

Can you help me?
Mar 11 '08 #8
Plater
7,872 Expert 4TB
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
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...
3
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 ...
4
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...
11
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.