I have a question regarding including a file after it has been copied to the program debug directory.
I have a WPF data grid and in this data grid I display a list of staff with the columns name, age and photo. I can double click a row to open up a new window to update the details and this includes the photo.
In my project directory, I have these folders which I have included in my project. The default folder consists of .jpg files of default staff member photos and the userData folder will be used to store user uploaded photos.
In my .csproj
file I have included this:
<ItemGroup>
<Content Include="img\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
This ensures that the img
folder gets copied to the output directory upon build. I have also added a .txt
file in the userData
folder as otherwise it does not copy the folder.
When the user uploads the photo and hits save in my program, it does two things:
- Copies the file from source to the output directory of relative path
img\userData\filename.jpg
- Updates the SQLite record for that staff member's photo path, e.g. From
img\default\staffmember1default.jpg
toimg\userData\newstaffmember1.jpg
My program currently does not update the data grid to reflect changes so upon closing and running the program, it displays a blank photo for the staff member that had the photo change. However, if I was to copy that photo into the included img\userData
directory in my project and reload the program it works.
Is there a way to get around this and allow it to display the new photo from the userData
directory? Is this whole method suitable or is there a better way of tackling this whole process?