|
-
Dec 5th, 2007, 03:25 AM
#1
Thread Starter
Addicted Member
[RESOLVED] [2005] get the filename only from the open file dialog
Hi guys,
I have 2 questions
1. I wanna save a picture but only the filename only not the whole path.
how do I do that using open file dialog.
2. Let say I did save that file, how do I copy that file from the origin path to
specific path
Thanks guys.
effort effort effort and still effort
-
Dec 5th, 2007, 04:18 AM
#2
Lively Member
Re: [2005] get the filename only from the open file dialog
use openfiledialogue.filename property
-
Dec 5th, 2007, 04:28 AM
#3
Thread Starter
Addicted Member
Re: [2005] get the filename only from the open file dialog
but it stores the whole path. like "C:/blabla/hkbkabek/a.jpg"
I just want the a.jpg. thanks for helping anyway.
effort effort effort and still effort
-
Dec 5th, 2007, 04:32 AM
#4
Lively Member
Re: [2005] get the filename only from the open file dialog
-
Dec 5th, 2007, 04:42 AM
#5
Frenzied Member
Re: [2005] get the filename only from the open file dialog
Actually, no
do
vb.net Code:
TempFile As New System.IO.FileInfo(ofd.FileName)
TempFile.Name (the name includes the extension)
-
Dec 5th, 2007, 11:10 AM
#6
Re: [2005] get the filename only from the open file dialog
another alternative would be:
Dim FileNameOnly As String = System.IO.Path.GetFileName(ofd.FileName)
Both Path.GetFileName and FileInfo work really well and is self documenting
-
Dec 5th, 2007, 03:16 PM
#7
Thread Starter
Addicted Member
Re: [2005] get the filename only from the open file dialog
GREAT!! I can't wait to try those codes. Anyway thank you for helping guys.
oh by the way is there anyone that could me for question # 2? I did some research last night, I tried it but it's not working. I will post my code later today because I am still at school.
effort effort effort and still effort
-
Dec 5th, 2007, 03:38 PM
#8
Re: [2005] get the filename only from the open file dialog
System.IO.File.Copy
Look it up on MSDN for a code example
-
Dec 5th, 2007, 04:31 PM
#9
Thread Starter
Addicted Member
Re: [2005] get the filename only from the open file dialog
yayyy the fileNameOnly works. I have one quick question.
in my form load I use the following code to load the image
Code:
currentRow = Me.BongoComicsDataSet.Characters.Rows(index)
lblName.Text = currentRow("name")
Pict1.Image = Image.FromFile("Characters\" & CStr(currentRow("image")))
it works just fine BUT everytime I add new picture I want automatically reload again the first picture, So what I did is using the same code to load it but it says FileNotFound. is the path changing everytime I add new picture from different folder?
it seems the program didn't know where is
Code:
Pict1.Image = Image.FromFile("Characters\" &CStr(currentRow("image")))
because when I add picture I add a picture form "My documents" or "desktop"
effort effort effort and still effort
-
Dec 5th, 2007, 04:37 PM
#10
Frenzied Member
Re: [2005] get the filename only from the open file dialog
The picture is created by you yes? and 'currentRow("image")' contains the path to the image?, and how are you creating a new picture?
-
Dec 5th, 2007, 04:45 PM
#11
Thread Starter
Addicted Member
Re: [2005] get the filename only from the open file dialog
This is how I add the new picture
Code:
fileNameOnly = System.IO.Path.GetFileName(OFD.FileName)
CharactersTableAdapter.Insert(txtName.Text, fileNameOnly, txtAKA.Text)
Me.Validate()
Me.CharactersTableAdapter.Update(Me.BongoComicsDataSet.Characters)
Me.CharactersTableAdapter.Fill(Me.BongoComicsDataSet.Characters)
Yes it contains the path BUT not the whole path. What I mean not the whole path is, it contains only "Characters/filename.jpg" not "C:\Documents and Settings\erika\My Documents\Visual Studio 2005\Projects\BongoComics\BongoComics\bin\Debug\Characters\filename.jpg"
it works fine if I put the whole code, but this codes won't work in someone else computer because the path might be different.
the same thing when I copy the picture from the sourcePath to destinationPath. It will work if I put the whole path.
this is my code to copy the file
Code:
My.Computer.FileSystem.CopyFile(filename, "C:\Documents and Settings\erika\My Documents\Visual Studio 2005\Projects\BongoComics\BongoComics\bin\Debug\Characters\" & fileNameOnly)
effort effort effort and still effort
-
Dec 5th, 2007, 04:50 PM
#12
Re: [2005] get the filename only from the open file dialog
if you are trying to indicate the current directory the application is running in (or a subdirectory of that) you should use Application.StartupPath
When you run your app, the actual EXE right now is located at
C:\Documents and Settings\erika\My Documents\Visual Studio 2005\Projects\BongoComics\BongoComics\bin\Debug\
However that is obviously not where it will always exist.
So the variable Application.StartupPath will be equal to
C:\Documents and Settings\erika\My Documents\Visual Studio 2005\Projects\BongoComics\BongoComics\bin\Debug\
if your exe was located in
c:\program files\my company\my app\
then that would be the value of application.startuppath (minus the final \)
So what I am getting at is, try
Code:
My.Computer.FileSystem.CopyFile(filename, Application.StartupPath & "\characters\" & filenameonly)
-
Dec 5th, 2007, 04:55 PM
#13
Thread Starter
Addicted Member
Re: [2005] get the filename only from the open file dialog
AWESOME kleinma!!! thanks a lot. Thank you all guys. I really appreciate it.
effort effort effort and still effort
-
Nov 11th, 2015, 09:54 AM
#14
New Member
Re: [2005] get the filename only from the open file dialog
 Originally Posted by ayahnabunda
but it stores the whole path. like "C:/blabla/hkbkabek/a.jpg"
I just want the a.jpg. thanks for helping anyway.
use this code:
dim filnam as string = OpenFileDialog.SafeFileName
-
Nov 11th, 2015, 10:30 AM
#15
Re: [2005] get the filename only from the open file dialog
 Originally Posted by zgjir
use this code:
dim filnam as string = OpenFileDialog.SafeFileName
The OFD didn't have that back in 2007, this is a super old thread & needn't be brought up again.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|