Solved

File Location Code

Posted on 2006-10-25
3
168 Views
Last Modified: 2010-04-16
Hi,
What code would I use if I wanted a picturebox to be populated with image that by default should be in the following path:

C:\Program Files\Application X\Images

But lets say the user installs the program to

C:\Program Files\Application B\Images

I guess what I am trying to ask is what code can i use so that no matter where the user installe the program the image file is always being pulled one level below the root application?

I have been play around with the following code and I am stilll having issues with it.

ResultantImage.Image = Image.FromFile(@"..\\..\\SnowFlake001.bmp");

Thanks

Peter
0
Comment
Question by:schenkp
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
Expert1701 earned 500 total points
ID: 17808370
Try,

  ResultantImage.Image = Image.FromFile(@"Images\SnowFlake001.bmp");

or,

  ResultantImage.Image = Image.FromFile(@".\Images\SnowFlake001.bmp");

or, to ignore the "working directory" and locate a file relative to the executing application:

  System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase), @"Images\SnowFlake001.bmp")
0
 
LVL 21

Expert Comment

by:theGhost_k8
ID: 17809966
app.path will give u current exe path
do whatever thereafter
0
 
LVL 21

Expert Comment

by:theGhost_k8
ID: 17809975
sorry its this:

AppDomain.CurrentDomain.BaseDirectory
or
Application.StartupPath()
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question