The process cannot access the file 'xyz' ..
Bonjour à tous,
J'ai un DataGridView, avec une colonne contenant des images.
L'affichage est ok, l'ajout et la supression d'un ROW aussi.
Mais une fois que je souhaite modifier une image (la remplacer par une autre), j'ai l'erreur suivante :
The process cannot access the file 'C:\BooBooking\News\news-5.jpg' because it is being used by another process."
Car j'essaye de supprimer l'image existante, et ensuite en ajouter une ...
Voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10
|
Try
If My.Computer.FileSystem.FileExists(fullPath) Then
Table_NewsDataGridView.SelectedRows(0).Cells("DataGridViewTextBoxColumnImage").Value = Nothing
My.Computer.FileSystem.DeleteFile(fullPath)
End If
My.Computer.FileSystem.CopyFile(.FileName, fullPath)
Catch ex As Exception
MsgBox(ex.Message())
End Try |
Voici le code de l'affichage : (dans CellFormatting)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| Dim mainPath, newsID As String
mainPath = My.Settings.MainPath()
Dim newsRow() As Data.DataRow
newsID = Table_NewsDataGridView.Rows(e.RowIndex).Cells("DataGridViewTextBoxColumnID").Value
If (Not (newsID = Nothing)) And (newsID > 0) Then
newsRow = Me.BoobooBDDataSet.Table_News.Select("ID ='" + newsID.ToString() + "'")
Dim strFilename As String = mainPath + "\" + newsRow(0)("Image")
Try
If (My.Computer.FileSystem.FileExists(strFilename)) Then
'theImage = Image.FromFile(strFilename)
e.Value = Bitmap.FromFile(strFilename)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If |
Avez vous une idée pour dé-référencer l'image avant de pouvoir la supprimer et la remplacer ?
Merci