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
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