Index was out of range. Must be non-negative and less than the size of
the collection.
Parameter name: index
Line 38: Protected Sub GridView1_RowDeleting(ByVal sender As
Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs)
Handles GridView1.RowDeleting
Line 39: e.Cancel = True
Line 40: Dim fileName As String = (CType(GridView1.Rows
(e.RowIndex).FindControl("FileLink"), HyperLink)).Text
Line 41:
Line 42: fileName = Path.Combine(Server.MapPath("/
fileupload"), fileName)
On Nov 11, 10:50 pm, CK <[EMAIL PROTECTED]> wrote:
> which line are you getting the error on?
>
> On 11 Nov, 10:14, nag <[EMAIL PROTECTED]> wrote:
>
>
>
> > hello i traced the my program and saw it works properly but when i run
> > directly i am getting following error..
>
> > Index was out of range. Must be non-negative and less than the size of
> > the collection.
> > Parameter name: index
> > please help to correct the error
> > On Nov 11, 1:55 pm, CK <[EMAIL PROTECTED]> wrote:
>
> > > you can limit to PDF files only by changing Dim files() As String =
> > > Directory.GetFiles(folder) to Dim files() As String =
> > > Directory.GetFiles(folder, "*.pdf").
>
> > > For your error, try stepping through the code in debug mode and see
> > > what happens.
>
> > > On 11 Nov, 06:17, nag <[EMAIL PROTECTED]> wrote:
>
> > > > hi
> > > > i have done for listing of files from folder and provided option to
> > > > delete.but i want list only pdf files can any one help me. and another
> > > > problem is when i delete selected file following errors come.
>
> > > > Index was out of range. Must be non-negative and less than the size of
> > > > the collection.
> > > > Parameter name: index
>
> > > > here is my code
>
> > > > <fieldset style="width: 804px" align="center">
>
> > > > <legend>Uploading and Deleting Files via Form</legend>
> > > > <div align="left" style="text-align: center">
> > > > <form id="form1" runat="server">
> > > > <asp:Label ID="labelStatus" runat="server"></asp:Label><br />
> > > > <asp:FileUpload ID="FileUpload1" runat="server" /><br />
> > > > <asp:Button ID="Button1" runat="server" Text="Upload"
> > > > OnClick="Button1_Click" /><br /><br />
>
> > > > <asp:GridView ID="GridView1" runat="server" DataSource="<%#
> > > > GetUploadList() %>" OnRowDeleting="GridView1_RowDeleting"
> > > > AutoGenerateColumns="False" >
> > > > <Columns>
> > > > <asp:TemplateField HeaderText="Uploaded File">
> > > > <ItemStyle HorizontalAlign="Center" Width="70%" />
> > > > <ItemTemplate>
> > > > <asp:HyperLink
> > > > ID="FileLink"
> > > > NavigateUrl='<%# "/vsjayanti/subpage/" +
> > > > Container.DataItem.ToString() %>'
> > > > Text='<%# Container.DataItem.ToString() %>'
> > > > runat="server" Target="_blank" />
> > > > </ItemTemplate>
> > > > </asp:TemplateField>
> > > > <asp:TemplateField HeaderText="Delete?">
> > > > <ItemStyle HorizontalAlign="Center" Width="30%" />
> > > > <ItemTemplate>
> > > > <asp:LinkButton ID="LinkButton1" runat="server"
> > > > CausesValidation="False" CommandName="Delete"
> > > > OnClientClick='return confirm("Are you sure you
> > > > want to delete this entry?");'
> > > > Text="Delete?" />
> > > > </ItemTemplate>
> > > > </asp:TemplateField>
> > > > </Columns>
> > > > </asp:GridView>
> > > > </form>
> > > > </div>
> > > > </fieldset>
>
> > > > Imports System.IO
>
> > > > Partial Class _Default
> > > > Inherits System.Web.UI.Page
>
> > > > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
> > > > System.EventArgs) Handles Me.Load
>
> > > > End Sub
>
> > > > Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
> > > > MyBase.OnLoad(e)
> > > > If (Not IsPostBack) Then
> > > > GridView1.DataBind()
> > > > End If
> > > > End Sub
>
> > > > Protected Function GetUploadList() As String()
> > > > Dim folder As String = Server.MapPath("/subpage")
>
> > > > Dim files() As String = Directory.GetFiles(folder)
> > > > Dim fileNames(files.Length - 1) As String
> > > > Array.Sort(files)
>
> > > > For i As Integer = 0 To files.Length - 1
> > > > fileNames(i) = Path.GetFileName(files(i))
> > > > Next i
>
> > > > Return fileNames
> > > > End Function
>
> > > > Protected Sub UploadThisFile(ByVal upload As FileUpload)
> > > > If upload.HasFile Then
> > > > Dim theFileName As String = Path.Combine(Server.MapPath("/
> > > > subpage"), upload.FileName)
> > > > upload.SaveAs(theFileName)
> > > > labelStatus.Text = "<b>File has been uploaded.</b>"
> > > > End If
> > > > End Sub
>
> > > > Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal
> > > > e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles
> > > > GridView1.RowDeleting
> > > > e.Cancel = True
> > > > Dim fileName As String =
> > > > (CType(GridView1.Rows(e.RowIndex).FindControl("FileLink"),
> > > > HyperLink)).Text
>
> > > > fileName = Path.Combine(Server.MapPath("/subpage"), fileName)
> > > > File.Delete(fileName)
> > > > GridView1.DataBind()
> > > > End Sub
>
> > > > Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
> > > > System.EventArgs) Handles Button1.Click
> > > > UploadThisFile(FileUpload1)
> > > > GridView1.DataBind()
> > > > End Sub
> > > > End Class- Hide quoted text -
>
> > > - Show quoted text -- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -