Solved

Help with uploading image from Windows App (VS2010)

Posted on 2012-12-23
2
305 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

728 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