cameradialog.initialdirectory file.exist

I use File.Exists(cameraDialog.InitialDirectory & currFileName) with currFilename the full name of the file.

Problem is that initialdirectory is empty and I need to test if file already exist, if yes, change the filename and test again.

How can I test if filename already exist?

This is my code used:

            currFileName = Me.txtBonNr.Text & "-" & LPAD(3, ivolgNr.ToString, "0") & ".jpg"
            Do While File.Exists(cameraDialog.InitialDirectory & currFileName)
                ivolgNr += 1
                currFileName = Me.txtBonNr.Text & "-" & LPAD(3, ivolgNr.ToString, "0") & ".jpg"
            Loop
            cameraDialog.DefaultFileName = currFileName
            cameraDialog.Title = "Foto: " & currFileName

Open in new window

LVL 2
IT-FactoryAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
See if this works better:
currFileName = Path.Combine(cameraDialog.InitialDirectory, String.Format("{0}-{1:000}.jpg", Me.txtBonNr.Text, ivolgNr))

Do While File.Exists(cameraDialog.InitialDirectory & currFileName)
    ivolgNr += 1
    currFileName = Path.Combine(cameraDialog.InitialDirectory, String.Format("{0}-{1:000}.jpg", Me.txtBonNr.Text, ivolgNr))
Loop

cameraDialog.DefaultFileName = currFileName
cameraDialog.Title = "Foto: " & currFileName

Open in new window

0
käµfm³d 👽Commented:
Correction:
currFileName = Path.Combine(cameraDialog.InitialDirectory, String.Format("{0}-{1:000}.jpg", Me.txtBonNr.Text, ivolgNr))

Do While File.Exists(currFileName)
    ivolgNr += 1
    currFileName = Path.Combine(cameraDialog.InitialDirectory, String.Format("{0}-{1:000}.jpg", Me.txtBonNr.Text, ivolgNr))
Loop

cameraDialog.DefaultFileName = currFileName
cameraDialog.Title = "Foto: " & currFileName

Open in new window

0
IT-FactoryAuthor Commented:
The problem is not the variable currfilename, that's ok.

The problem is that at the time the test File.exist is executed the property cameradialog.InitialDirectory is empty so results in \1234-001.jpg
But when cameradialog is ended and the file is saved the location is not \1234-001.jpg but is "\\My Documents\My Pictures\1234-001.jpg

So the propery cameradialog.Filename is set to 1234-001.jpg and after save it has the value \\My Documents\My Pictures\1234-001.jpg

I need the full path at the time the test is executed...(file.exist), the path that cameradialog uses for saving files.
0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

käµfm³d 👽Commented:
So is correct directory name achieved at the start, or end of cameradialog?
0
IT-FactoryAuthor Commented:
At the start I initiate it with only the filename (cameraDialog.DefaultFileName = currFileName) at this moment because I can't get the current dir of cameradialog, it is always empty.

I need to know the dir where the file will be saved. So I can concatinate dir + filename to check if already exists. if exist change filename and test again. Or use the dir + filename to initiate it (cameraDialog.DefaultFileName = dir & currFileName)

I found this:
Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);

but it is C# but when I change this to vb syntax the MyPictures is not valid.
0
CodeCruiserCommented:
Why not do the check after showing the dialog then? Or better still, why not use the CheckFileExists property of the save file dialog which automatically shows the warning if the file already exists

http://msdn.microsoft.com/en-us/library/system.windows.forms.filedialog.checkfileexists.aspx
0
IT-FactoryAuthor Commented:
because when I reach cameradialog return value (the moment the picture is taken), the file is already saved so its too late to act then.

It would also help to know in front what the location will be.

But this line won't work, he does not know mypictures

FilePath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)
0
CodeCruiserCommented:
Can you describe the sequence of code? What camera and picture are you talking about?
0
hjgodeTier 3 Senior Technical Support EngineerCommented:
Hello

sorry for jumping in, but I believe I understand your need.

The CameraCaptureDialog is a separate app and you can not enforce the user to use a special dir or name of a captured still image. You can specify an initial dir and a default file name, but the user may change these. When the dialog ends you get a DialogResult and if this is OK you can get the file name (and dir) the user has chosen to save the image.
Now you can move/rename the image file to your scheme, but this is after the cameracapturedialog has been closed. You can then inform the user and show the dir and file name you have enforced.

I don't see another way to enforce a dir or filename convention. The CameraDialog was not designed for this.

regards

Josef
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MedievalWarriorCommented:
Here are two alternative options you don't need to check if the file exists.
// option 1
string defaultFileName = System.IO.Path.ChangeExtension(Guid.NewGuid().ToString("N"), ".jpg");
Console.WriteLine(defaultFileName);

// option 2
string defaultFileName2 = System.IO.Path.ChangeExtension(System.IO.Path.GetRandomFileName(), ".jpg");
Console.WriteLine(defaultFileName2);

Open in new window

0
IT-FactoryAuthor Commented:
ok back in the running...
ok I test the last 2 comments
0
IT-FactoryAuthor Commented:
You are right this is not changeable so I left it as it is and moved the file afterwards.

Thanks for getting me in the right way.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Smartphone Programming

From novice to tech pro — start learning today.