Include files in project

johmolan

Well-known member
Joined
Oct 11, 2008
Messages
129
Programming Experience
Beginner
I have included 2 pdf files in my Project. I have set their property to embedded resource. and copy to output directory to: copy allways.

I list them up in a listbox using the code:
VB.NET:
Public Sub FillList()
        Dim folderInfo As New IO.DirectoryInfo(My.Application.Info.DirectoryPath)
        Dim arrFilesInFolder() As IO.FileInfo
        Dim fileInFolder As IO.FileInfo
        arrFilesInFolder = folderInfo.GetFiles("*.pdf")
        For Each fileInFolder In arrFilesInFolder
            ListBox1.Items.Add(fileInFolder.Name)
        Next
       

    End Sub

When I build the project the files are in the list and it all works great, but when I publish the project and install it, the files does not appear in the list anymore, why is that and how can I make them follow in the publish and insallation of the program in a way that they will appear in my list after I hav installed it??
 
I think what's going on is on your computer the app is using the files from the folder instead of extracting the files from the exe. Which means it works on your local machine because they do exist, but when you deploy it (publish it) your code's expecting those files to be there, but since they're embedded in the exe file (that's what an embedded resource is) they dont exist in the project folder.

What you should do is either set the files in the solution explorer to be content and set them to be copied to the output directory, then just change your code to use Application.StartUpPath (Include any folders they may be in after App Startup Path too) and then the publish will work as you'd expect

Or keep them as embedded resources and change the code to extract them to the temp dir in the user's account and use them from there.

I can help with either method here..
 
Back
Top