Question Works in debug mode but not once published

Bozz

Member
Joined
Jul 28, 2009
Messages
14
Programming Experience
Beginner
Beginner here, VB2008 Express. My program will allow me to browse, move and delete images just fine in debug mode, but once published to the desktop, it wont let me move or delete. Instead it gives me my handled exception, a messagebox. What's up with that? I suspect some kind of permission thing which I know very little about.
 
Whats the error? Could we see some code as well?

Could be permissions issue, but if it worked in debug mode i don't see why it wouldn't work outside of debug mode. Is it the same PC?

It also could be a directory error. When you run it on your desktop you are running the application in a different directory than when you run it in debug mode.
 
Thanks for responding.
Here is a very simplified barebones version of my image viewer/copier program
It has one PictureBox, four Button, and two FolderBrowserDialog.


Imports System.IO

Public Class Form1
Dim FromFolder As String
Dim ToFolder As String
Dim ImageFiles() As String
Dim ImageFilesCount As Integer
Dim Index As Integer
Dim CurrentImage As String

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'establish From and To folders
FromFolder = Directory.GetCurrentDirectory
ToFolder = Directory.GetCurrentDirectory
ImageFinder()
ImageLoader()
End Sub

Private Sub ImageFinder()
'find images in the From folder and place them in an array
Dim AllowedExtensions() As String = {".bmp", ".gif", ".jpe", ".jpg", ".jpeg", ".png", ".tif"}
Dim AllFiles() As String = Directory.GetFiles(FromFolder, "*.*")
Dim MyArrayList As New ArrayList
For Each File As String In AllFiles
For Each AllowedExtension As String In AllowedExtensions
If AllowedExtension = Path.GetExtension(File).ToLower Then
MyArrayList.Add(File)
End If
Next
Next
ImageFiles = MyArrayList.ToArray(GetType(String))
End Sub

Private Sub ImageLoader()
'load an image into the picture box
ImageFilesCount = ImageFiles.Length
If ImageFilesCount > 0 Then
PictureBox1.Load(ImageFiles(Index))
CurrentImage = Path.GetFileName(ImageFiles(Index))
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'choose a different From folder
FolderBrowserDialog1.SelectedPath = FromFolder
If (FolderBrowserDialog1.ShowDialog() = DialogResult.OK) Then
FromFolder = FolderBrowserDialog1.SelectedPath
ImageFinder()
ImageLoader()
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'choose a To folder
FolderBrowserDialog2.SelectedPath = ToFolder
If (FolderBrowserDialog2.ShowDialog() = DialogResult.OK) Then
ToFolder = FolderBrowserDialog2.SelectedPath
End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'flip through images in the From folder
If ImageFilesCount > 0 Then
If Index > 0 Then
Index -= 1
ImageLoader()
Else
Index = ImageFilesCount - 1
ImageLoader()
End If
End If
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
'copy CurrentImage from From folder to To folder
If ImageFilesCount > 0 Then
Try
File.Copy(CurrentImage, (ToFolder + "\" + CurrentImage), False)
MsgBox(CurrentImage & " copied successfully")
Catch ex As Exception
MsgBox(CurrentImage & " not copied (or may already exists in this folder)")
End Try
End If
End Sub
End Class

Works fine in debug mode. I built it, published it to the desktop, and ran setup. It will browse images etc. fine, but not allow me to copy.
Thanks for any help.
 
Problem Solved

Found the Problem. You were right rcombs4. It was a directory issue.
This line:
File.Copy(CurrentImage, (ToFolder + "\" + CurrentImage), False)
should be:
File.Copy(FromFolder + "\" + CurrentImage, (ToFolder + "\" + CurrentImage), False)
Thanks for your help.
 
Back
Top