Solved

Help with uploading image from Windows App (VS2010)

Posted on 2012-12-23
2
300 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
Comment Utility
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
Comment Utility
Thank You!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now