473,473 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

deleting file referenced from gridview???

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
Nov 19 '05 #1
0 1390

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Alex | last post by:
Hi, I have two tables , A and B where table B has a foreign key constraint to table A. I want to delete all records in table A that are older than a certain date that are not referenced by...
3
by: adam222 | last post by:
hello, i have a web-form with a GridView control, i wanted to update & delete, using the AutoGenerateEditButton. when i used it with sqlDataSource (executing SP in the DB) it works like a...
2
by: loga123 | last post by:
Hi All, I am using Link Button for DELETE on the gridview. When I click on DELETE link, I get the ArgumentOutOfRangeException. But...it deletes the record from table in the database. On...
1
by: loga123 | last post by:
Hi All, I am using Link Button for DELETE on the gridview. When I click on DELETE link, I get the ArgumentOutOfRangeException. But...it deletes the record from table in the database. On...
0
by: Wannabe | last post by:
I have been trying to figure this out for days now...can someone please help? I am using ASP.Net 2.0 and have a gridview on my page. I have everything working except the delete command. The page...
0
by: TheDebbis | last post by:
I'm making a quick CD catalog to help me learn ASP.NET (using C# primarily.) I have a number of gridview's on my site that are working properly, but for some reason, one is not updating or deleting....
1
by: manojpolawar2008 | last post by:
Hi , i am using asp.net2.0 in that DirectoryInfo object for reading the files. i have added each file record to DataTable object. and bind that to gridview and added one templete...
0
by: Andy B | last post by:
I have the following gridview. There are 2 other textBoxes and a button on the page as well. When somebody puts text into the 2 textBoxes and presses the add button, it puts the values of those...
1
by: Vajrala Narendra | last post by:
Hi, all am working on asp.net, c# 2.0 i want to delete a row from a grid view for that i take datakeyname inn gris view i wrote coding as 1. <asp:GridView ID="GridView2" runat="server"...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.