473,398 Members | 2,212 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,398 software developers and data experts.

Help me to avoid again & again changing the path...........

9
Hi,
I want to change the BackgroundImage of form and i have created the folder named Images in my project and i will change the BackgroundImage when user press any key and I try it on different PC & always I have to change the path of it, so any other method anyone know to keep path constant then please tell me....

Expand|Select|Wrap|Line Numbers
  1. BackgroundImage = Image.FromFile("C:/Users/HOME/Documents/Visual Studio 2008/Projects/Patient Testing/Patient Testing/Images/" + pic[count].ToString() + ".jpg");
  2.  
Thank you...
Sep 6 '10 #1
8 1543
Aimee Bailey
197 Expert 100+
This should do the trick:

Expand|Select|Wrap|Line Numbers
  1. string AppPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"Images\\");
  2.             MessageBox.Show(AppPath);
  3.  
Remember to add using System.IO to the top of your code.

Aimee.
Sep 7 '10 #2
Plater
7,872 Expert 4TB
For the most part: If the images directory is in the same place as the exe, using relative paths might work.
Otherwise consider:
string dir=Path.Combine(AppDomain.CurrentDomain.BaseDirec tory,"Images");
Sep 7 '10 #3
Mahyog
9
Thanx but it gives me the path

Expand|Select|Wrap|Line Numbers
  1. C:\Users\HOME\Documents\Visual Studio 2008\Projects\Patient Testing\Patient Testing\bin\Debug\Images\4.jpg
  2.  
but I want path.

Expand|Select|Wrap|Line Numbers
  1. C:\Users\HOME\Documents\Visual Studio 2008\Projects\Patient Testing\Patient Testing\Images\4.jpg
  2.  
Sep 8 '10 #4
Christian Binder
218 Expert 100+
Try the following^:

Path.Combine(AppDomain.CurrentDomain.BaseDirectory , @"..\..\Images");
Sep 8 '10 #5
Mahyog
9
This also not working...

Expand|Select|Wrap|Line Numbers
  1. C:\Users\HOME\Documents\Visual Studio 2008\Projects\Patient Testing\Patient Testing\bin\Debug\Images\4.jpg
  2.  
I dont want to go in bin and Debug folder my Images folder is in following way...

Expand|Select|Wrap|Line Numbers
  1. C:\Users\HOME\Documents\Visual Studio 2008\Projects\Patient Testing\Patient Testing\Images\4.jpg
  2.  
Sep 9 '10 #6
Christian Binder
218 Expert 100+
My suggestion would/should create the following:
Expand|Select|Wrap|Line Numbers
  1. C:\Users\HOME\Documents\Visual Studio 2008\Projects\Patient Testing\Patient Testing\bin\Debug\..\..\Images\4.jpg
  2.  
If you open this path, it would open the file
Expand|Select|Wrap|Line Numbers
  1. C:\Users\HOME\Documents\Visual Studio 2008\Projects\Patient Testing\Patient Testing\Images\4.jpg
  2.  
because "..\" means one folder up in hierarchy.

Alternatively you could do the following:
Expand|Select|Wrap|Line Numbers
  1. string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Images"); 
  2. path = path.Replace(@"\bin\Debug", "");
  3.  
Sep 9 '10 #7
Plater
7,872 Expert 4TB
Your project will never work if you don't tell visual studio that your images directory is content to be copied to the ouput directory (and thus, part of the project). When you get that fixed, you can use the code I provided.
Sep 9 '10 #8
Keep your images in same directory where your application.exe exists and just specify image filename in your code.
For example:
BackgroundImage = "xyz.jpg";
Oct 8 '10 #9

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

Similar topics

2
by: Jody Burgess | last post by:
Hi; I am writing my first python program and would like to know how to change stdout to refer to my default printer or any other printer on my network. The other question is, Is there an API set...
1
by: hibernate | last post by:
I'm just learning CSS, so I'm not aware of it's capabilities. As an example my problem is that I have many different images with identical names, within three seperate folders. so, in my root...
5
by: Arpan | last post by:
An ASP application retrieves records from a SQL Server database. In the first page of the application, the user has to enter a password & the columns retrieved from the DB table depends upon the...
2
by: kma | last post by:
I am designing an Access 2000 database on a computer running Windows 98. I have one form with several tabs; all of which have sub forms, some with a subform on a subform. For example, on my...
2
by: ray well | last post by:
hi, how can i open and close a help file thru code? i tried dim procHelp as System.Diagnostics.Process procHelp = System.Diagnostics.Process.Start("help.hlp"), it did open
3
by: moumita | last post by:
I want to create a form and display multiple symbols on it.The problem is how do I create and store the symbols so that I can display one single symbol multiple number of times on the form without...
7
by: Dan | last post by:
(Using Classic ASP & MS Access) I have a page that has 120 fields on it (mostly checkboxes). I cannot split this into smaller pages. So what i want to do is write a class that handles this. in...
14
by: Arne | last post by:
A lot of Firefox users I know, says they have problems with validation where the ampersand sign has to be written as & to be valid. I don't have Firefox my self and don't wont to install it only...
30
by: Alf P. Steinbach | last post by:
I once suggested in that SomeOne Else(TM) should propose a string value class that accepted literals and char pointers and so on, with possible custom deleter, and in case of literal strings just...
7
by: franc sutherland | last post by:
Hi everyone, I am using Access 2003. I have a database with a table in it which is linked to an excel spreadsheet. When I install the database on someone else's system, the pathname to the...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
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...
0
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,...

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.