Solved

File Location Code

Posted on 2006-10-25
3
164 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

862 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now