deleting file referenced from gridview???

B

Bandit

I'm populating a gridview (called docList) with document info from a
network folder like so:

Sub Show_Files(ByVal inputDir As String)
Dim strFileNamePath As String = inputDir
Dim dirInfo As DirectoryInfo = New DirectoryInfo(strFileNamePath)
Dim aFiles As FileInfo() = dirInfo.GetFiles("*.doc")
Array.Sort(aFiles, New CompareFileInfoEntries
(CompareByOptions.LastWriteTime))
docList.DataSource = aFiles
docList.DataBind()
End Sub

This works fine and the gridview shows all files in the folder with a
command button for deleting. However when I try to delete a file like so:

Sub Row_Deleting(ByVal Src As Object, ByVal Args As
GridViewDeleteEventArgs)
If File.Exists(e.Keys("Name").ToString) Then
File.Delete(e.Keys("Name").ToString)
End If
End Sub

I get the following message:

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not
set
to an instance of an object.

Source Error:

Line 25:
Line 26: Sub Row_Deleting(ByVal Src As Object, ByVal Args As
GridViewDeleteEventArgs)
Line 27: If File.Exists(Args.Keys("Name").ToString) Then
Line 28: File.Delete(Args.Keys("FullName").ToString)
Line 29: End If

This is driving me nuts, I've tried everything I know to try and get a
file name from the GridViewDeleteEventArgs to delete the file but with no
success. Help!

Davy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top