deleting file referenced from gridview???

Discussion in 'ASP .Net' started by Bandit, Mar 8, 2005.

  1. Bandit

    Bandit Guest

    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
     
    Bandit, Mar 8, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luis Esteban Valencia Muñoz
    Replies:
    3
    Views:
    1,445
    Scott Allen
    Jun 4, 2005
  2. Replies:
    2
    Views:
    558
  3. Harry Barker
    Replies:
    2
    Views:
    544
    Alf P. Steinbach
    Apr 19, 2006
  4. Sven S.
    Replies:
    1
    Views:
    134
    Sven S.
    Mar 23, 2010
  5. crea
    Replies:
    2
    Views:
    442
    Nobody
    Dec 28, 2012
Loading...

Share This Page