Solved

Help with uploading image from Windows App (VS2010)

Posted on 2012-12-23
2
304 Views
Last Modified: 2012-12-28
I am using the code below to upload an image but I get an error message if the file already exist. How do I check if the file already exist and if it does inform users with a message box?
 
Dim DestinationPath As String = Application.StartupPath & "\Images\" & IO.Path.GetFileName(C1Image.Text)
        IO.File.Copy(C1Image.Text, DestinationPath)

Thanks,

Victor
0
Comment
Question by:vcharles
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 38717477
Try something like:
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim DestinationPath As String = IO.Path.Combine(Application.StartupPath & "\Images", IO.Path.GetFileName(C1Image.Text))
        If IO.File.Exists(DestinationPath) Then
            If MessageBox.Show("Destination already exists!" & vbCrLf & vbCrLf & "File: " & DestinationPath, "Replace File?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                IO.File.Copy(C1Image.Text, DestinationPath, True)
            End If
        Else
            IO.File.Copy(C1Image.Text, DestinationPath)
        End If
    End Sub

Open in new window

0
 

Author Comment

by:vcharles
ID: 38717524
Thank You!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.

749 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