473,499 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

directories and application path

Hi all,

I would like to open an OpenFileDialog to find an image and store it in the
folder of my application, so I can refere to it in the future only by
"./picture/file".
My code looks like that:

//openFileDialog and set up Filter,Title and Initial Directory
openFileDialog1.Filter = "Bitmap Image(*.bmp)|*.bmp|GIF Image
(*.gif)|*.gif|JPEG Image(*.jpg)|*.jpg|All files (*.*)|*.*" ;
openFileDialog1.Title = "Choose a picture";
openFileDialog1.InitialDirectory = "C:\\";

if (openFileDialog1.ShowDialog()== DialogResult.OK)
{
pictureBox1.Image=Image.FromFile(openFileDialog1.F ileName);
System.IO.FileInfo MyFile=new
System.IO.FileInfo(openFileDialog1.FileName);
MyFile.CopyTo(@".\Picture\"+MyFile.Name,true);
PicturePath=".\\Picture\\"+MyFile.Name;
}

now the problem is that if I do like that it will create a folder "Picure"
in each directory I have found the image! How could I set up the directory
of my application?
Thank you very much,

Bart
Nov 16 '05 #1
3 1266
Hi Bart,

Is this what you you looking for: Application.StartupPath?

HTH,
Rakesh Rajan

"Bart" wrote:
Hi all,

I would like to open an OpenFileDialog to find an image and store it in the
folder of my application, so I can refere to it in the future only by
"./picture/file".
My code looks like that:

//openFileDialog and set up Filter,Title and Initial Directory
openFileDialog1.Filter = "Bitmap Image(*.bmp)|*.bmp|GIF Image
(*.gif)|*.gif|JPEG Image(*.jpg)|*.jpg|All files (*.*)|*.*" ;
openFileDialog1.Title = "Choose a picture";
openFileDialog1.InitialDirectory = "C:\\";

if (openFileDialog1.ShowDialog()== DialogResult.OK)
{
pictureBox1.Image=Image.FromFile(openFileDialog1.F ileName);
System.IO.FileInfo MyFile=new
System.IO.FileInfo(openFileDialog1.FileName);
MyFile.CopyTo(@".\Picture\"+MyFile.Name,true);
PicturePath=".\\Picture\\"+MyFile.Name;
}

now the problem is that if I do like that it will create a folder "Picure"
in each directory I have found the image! How could I set up the directory
of my application?
Thank you very much,

Bart

Nov 16 '05 #2
Hello Bart,

Try this:

openFileDialog1.InitialDirectory =
Environment.GetFolderPath(Environment.SpecialFolde r.MyPictures);
openFileDialog1.Multiselect = true;

if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string dest = Application.StartupPath + @"\Picture";
if (Directory.Exists(dest) == false)
Directory.CreateDirectory(dest);

foreach (string picture in openFileDialog1.FileNames)
{
string filename = picture.Remove(0, picture.LastIndexOf(@"\"));
File.Copy(picture, dest+filename);
}
}

Arne
Nov 16 '05 #3
Thanks to both of you,
I used and it works so nice!

"Bart" <ba**@bart.it> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi all,

I would like to open an OpenFileDialog to find an image and store it in the folder of my application, so I can refere to it in the future only by
"./picture/file".
My code looks like that:

//openFileDialog and set up Filter,Title and Initial Directory
openFileDialog1.Filter = "Bitmap Image(*.bmp)|*.bmp|GIF Image
(*.gif)|*.gif|JPEG Image(*.jpg)|*.jpg|All files (*.*)|*.*" ;
openFileDialog1.Title = "Choose a picture";
openFileDialog1.InitialDirectory = "C:\\";

if (openFileDialog1.ShowDialog()== DialogResult.OK)
{
pictureBox1.Image=Image.FromFile(openFileDialog1.F ileName);
System.IO.FileInfo MyFile=new
System.IO.FileInfo(openFileDialog1.FileName);
MyFile.CopyTo(@".\Picture\"+MyFile.Name,true);
PicturePath=".\\Picture\\"+MyFile.Name;
}

now the problem is that if I do like that it will create a folder "Picure"
in each directory I have found the image! How could I set up the directory
of my application?
Thank you very much,

Bart

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4792
by: Billy Jacobs | last post by:
I have a website which has both secure and non-secure pages. I want to uses forms authentication. How do I accomplish this? Originally I had my web.config file in the root with Forms...
6
3651
by: Eran Kampf | last post by:
I am trying to dynamically create directories in my ASP.NET application (I am using Server.MapPath("/")+"test" as the folder) and I am getting a DirectoryNotFoundException saying "Could not find a...
2
4208
by: Jeffry van de Vuurst | last post by:
Hi, (sorry for the crosspost, I wasn't sure which was the best place to put this). I was just thinking about something and wondered if any of you has some ideas about this. I'm using the...
4
3312
by: Grant Harmeyer | last post by:
How would I set up an httpHandler so that it would only apply to certain child directories of the application? I.E: <httpHandlers> <add verb="*" path="/files/*/*/*/*.aspx"...
3
1459
by: Stelrad Doulton | last post by:
Hi, I am having a strange problem on IIS 6.0. I am trying to create directories under a virtual directory on the fly to which I will upload files and retrieve these files later. I am having 2...
4
2204
by: Chuck P | last post by:
Using vs05 and making an asp.net 2.0 website. We use VSS and have everything organized like this SolutionName Documents Code WebProjectName1 WebServiceProjectName1
6
1769
by: Charlie Bear | last post by:
i'm really stuck with this one can anyone help! i have a website that uses c#. it creates a series of directories and files from an xml source. when the xml changes, the directory that the...
6
16986
by: =?Utf-8?B?WW9naSBXYXRjaGVy?= | last post by:
Hello, I am using Visual Studio-2003. I created a project to build my library. Since I am using third party libraries as well, I have specified those additional library dependencies in project...
4
2443
by: Jeff Nyman | last post by:
Greetings all. I did some searching on this but I can't seem to find a specific solution. I have code like this: ========================================= def walker1(arg, dirname, names):...
0
365
by: abtandon | last post by:
Hi All I just ported my ATL application from VS2005 to VS2008, I have included the required ATL server include directory path in "Additional Include Directories" in VS 2008 IDE...
0
7009
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
7178
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,...
1
6899
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
7390
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...
1
4919
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...
0
4602
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...
0
1427
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 ...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
302
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.