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 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
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
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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...
|
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"...
|
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...
| |
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
|
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...
|
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...
|
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):...
|
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...
|
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...
| |
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,...
|
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...
|
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: 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...
|
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...
|
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 ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |