rad upload inside grid issue

Thread is closed for posting
6 posts, 0 answers
  1. Adam
    Adam avatar
    7 posts
    Member since:
    Apr 2007

    Posted 05 Sep 2008 Link to this post

    Hey Guys,

    I am having issues with the rad upload version 2008.01.0416.20

    the issue that i am having is that it will upload some files, but not others. It will take .doc , .txt files and others but will not take .zip files .wav .mp3

    I found this because the app that i am using has a flier and a media file. I will post the code below, let me know where i am going wrong.


    Imports System 
    Imports System.Data 
    Imports System.Configuration 
    Imports System.Web 
    Imports System.Web.Security 
    Imports System.Web.UI 
    Imports System.Web.UI.WebControls 
    Imports System.Web.UI.WebControls.WebParts 
    Imports System.Web.UI.HtmlControls 
    Imports System.Data.OleDb 
    Imports System.IO 
    Imports Telerik.Web.UI 
     
    Partial Public Class sermons1 
        Inherits System.Web.UI.Page 
        Private Shared _connectionString As String = Nothing 
        Dim RandomClass As New Random() 
        Dim RandomNumber As String = RandomClass.Next().ToString 
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) 
            If Not IsPostBack Then 
                RadGrid1.MasterTableView.DataKeyNames = New String() {"ID"} 
            End If 
        End Sub 'Page_Load 
     
        Protected Sub RadGrid1_InsertCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.InsertCommand 
            If IsValid Then 
                Dim uploader As RadUpload = e.Item.FindControl("RadUpload1") 
                Dim uploader2 As RadUpload = e.Item.FindControl("RadUpload2") 
                Dim description As TextBox = e.Item.FindControl("txtDescription") 
                Dim datecreated As TextBox = e.Item.FindControl("txtdate") 
                Dim DropDownList1 As RadComboBox = e.Item.FindControl("DropDownList1") 
     
     
                '/// Pass sql statement to connection module for execution 
                Dim stridcreated As String 
                Dim imagename As String = "" 
                Dim imagename2 As String = "" 
                Dim filename As UploadedFile = Nothing 
                stridcreated = insertqry("INSERT INTO sermons ( [description], [datecreated],[cat]) VALUES ( '" & description.Text & "', '" & datecreated.Text & "q', '" & DropDownList1.SelectedValue.ToString & "'); ", ) 
     
                Dim targetFolder As String = Server.MapPath("~/uploads/") 
                Try 
     
                    filename = uploader.UploadedFiles(0) 
                    SaveFile(filename, targetFolder & stridcreated & filename.GetExtension()) 
                    imagename = stridcreated & filename.GetExtension() 
                Catch ex As Exception 
                End Try 
                Try 
                    filename = uploader2.UploadedFiles(0) 
                    SaveFile(filename, targetFolder & stridcreated & "_2" & filename.GetExtension()) 
                    imagename2 = stridcreated & "_2" & filename.GetExtension() 
                Catch ex As Exception 
                End Try 
                If uploader.UploadedFiles.Count > 0 And uploader2.UploadedFiles.Count > 0 Then 
                    updateqry("update sermons SET  [file]='" & imagename & "' WHERE [id] = " & stridcreated, ) 
                    updateqry("update sermons SET  [flier]='" & imagename2 & "' WHERE [id] = " & stridcreated, ) 
                ElseIf uploader.UploadedFiles.Count > 0 Then 
                    updateqry("update sermons SET  [file]='" & imagename & "' WHERE [id] = " & stridcreated, ) 
                ElseIf uploader2.UploadedFiles.Count > 0 Then 
                    updateqry("update sermons SET  [flier]='" & imagename2 & "' WHERE [id] = " & stridcreated, ) 
                Else 
                End If 
     
                SetMessage(stridcreated & " was the id created") 
            End If 
            RadGrid1.Rebind() 
        End Sub 'RadGrid1_InsertCommand 
     
        Protected Sub RadGrid1_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.UpdateCommand 
            Dim uploader As RadUpload = e.Item.FindControl("RadUpload1") 
            Dim uploader2 As RadUpload = e.Item.FindControl("RadUpload2") 
            Dim description As TextBox = e.Item.FindControl("txtDescription") 
            Dim datecreated As TextBox = e.Item.FindControl("txtdate") 
            Dim DropDownList1 As RadComboBox = e.Item.FindControl("DropDownList1") 
     
     
     
            Dim id As Integer = CInt(RadGrid1.MasterTableView.DataKeyValues(e.Item.ItemIndex)("ID")) 
     
     
            Dim imagename As String = "" 
            Dim imagename2 As String = "" 
            Dim filename As UploadedFile = Nothing 
            Try 
                filename = uploader.UploadedFiles(0) 
                SaveFile(filename, Server.MapPath("~/uploads/") & id & filename.GetExtension()) 
                imagename = id & filename.GetExtension() 
            Catch ex As Exception 
     
            End Try 
            Try 
                filename = uploader2.UploadedFiles(0) 
                SaveFile(filename, Server.MapPath("~/uploads/") & id & "_2" & filename.GetExtension()) 
                imagename2 = id & "_2" & filename.GetExtension() 
            Catch ex As Exception 
     
            End Try 
     
            If uploader.UploadedFiles.Count > 0 And uploader2.UploadedFiles.Count > 0 Then 
                DeleteFile(id) 
                updateqry("UPDATE sermons SET  [description]='" & description.Text & "', [cat]='" & DropDownList1.SelectedValue.ToString & "', [datecreated]='" & datecreated.Text & "' WHERE [id] = " & id) 
                updateqry("update sermons SET  [file]='" & imagename & "' WHERE [id] = " & id, ) 
                updateqry("update sermons SET  [flier]='" & imagename2 & "' WHERE [id] = " & id, ) 
            ElseIf uploader.UploadedFiles.Count > 0 Then 
                updateqry("UPDATE sermons SET  [description]='" & description.Text & "', [cat]='" & DropDownList1.SelectedValue.ToString & "', [datecreated]='" & datecreated.Text & "' WHERE [id] = " & id) 
                updateqry("update sermons SET  [file]='" & imagename & "' WHERE [id] = " & id, ) 
            ElseIf uploader2.UploadedFiles.Count > 0 Then 
                updateqry("UPDATE sermons SET  [description]='" & description.Text & "', [cat]='" & DropDownList1.SelectedValue.ToString & "', [datecreated]='" & datecreated.Text & "' WHERE [id] = " & id) 
                updateqry("update sermons SET  [flier]='" & imagename2 & "' WHERE [id] = " & id, ) 
            Else 
                updateqry("UPDATE sermons SET  [description]='" & description.Text & "', [cat]='" & DropDownList1.SelectedValue.ToString & "', [datecreated]='" & datecreated.Text & "' WHERE [id] = " & id) 
            End If 
            SetMessage("Record " & id & " was updated") 
            RadGrid1.Rebind() 
        End Sub 
     
     
     
        Protected Sub RadGrid1_DeleteCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.DeleteCommand 
            Dim id As Integer = CInt(RadGrid1.MasterTableView.DataKeyValues(e.Item.ItemIndex)("ID")) 
            ' Dim ID As String = CType(e.Item, GridDataItem)("CustomerID").Text 
            updateqry("DELETE FROM sermons WHERE [ID]= " & id, ) 
            RadGrid1.Rebind() 
        End Sub 
     
     
        Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) 
            If TypeOf e.Item Is Telerik.Web.UI.GridEditableItem And e.Item.IsInEditMode Then 
     
            End If 
        End Sub 
     
     
     
        Function SaveFile(ByVal Filetobesaved As UploadedFile, ByVal id As String) 
            Filetobesaved.SaveAs(id, True) 
            Return id 
        End Function 
     
     
     
        Protected Sub DeleteFile(ByVal id As String) 
            Try 
                Dim Filetobedeleted As String 
                For Each Filetobedeleted In Directory.GetFiles(Server.MapPath("~/upload") & id) 
                    File.Delete(Filetobedeleted) 
                Next Filetobedeleted 
            Catch ex As Exception 
                SetMessage("image could not be deleted, but it worked") 
            End Try 
     
        End Sub 
     
        Private Sub SetMessage(ByVal message As String) 
            gridMessage = message 
        End Sub 
     
        Private gridMessage As String = Nothing 
        Protected Sub RadGrid1_DataBound(ByVal sender As Object, ByVal e As EventArgs) Handles RadGrid1.DataBound 
            If Not String.IsNullOrEmpty(gridMessage) Then 
                DisplayMessage(gridMessage) 
            End If 
        End Sub 
        Private Sub DisplayMessage(ByVal text As String) 
            RadGrid1.Controls.Add(New LiteralControl(String.Format("<span style='color:red'>{0}</span>", text))) 
        End Sub 
        
      
    End Class 
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    <%@ Page Language="vb" AutoEventWireup="false" MasterPageFile="~/admin/admin.Master" CodeBehind="sermons.aspx.vb" Inherits="blackmansgrove.org.sermons1" %> 
     
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
     
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"
          
          
        <telerik:RadGrid runat="server" ID="RadGrid1" Skin="Vista"  
            EnableOutsideScripts="true" EnableAJAX="true" AllowPaging="True" 
            AllowSorting="True" AutoGenerateColumns="False" Width="97%" 
            DataSourceID="AccessDataSource1" AutoGenerateDeleteColumn="True" AutoGenerateEditColumn="True" 
            OnUpdateCommand="RadGrid1_UpdateCommand" OnInsertCommand="RadGrid1_InsertCommand" 
            OnDeleteCommand="RadGrid1_DeleteCommand"  OnItemDataBound="RadGrid1_ItemDataBound" 
            ShowStatusBar="True" GridLines="None"
           
            <PagerStyle Mode="NextPrevAndNumeric" /> 
                     <MasterTableView DataSourceID="AccessDataSource1" DataKeyNames="ID"   
                commanditemdisplay="Top"
                <Columns> 
                    <telerik:GridTemplateColumn UniqueName="TemplateColumn" SortExpression="ID"
                        <HeaderTemplate> 
                            <table> 
                                <tr> 
                                    <td style="width: 144px; height: 21px"
                                        ID 
                                    </td> 
                                    <td style="width: 198px; height: 21px"
                                        datecreated 
                                    </td> 
                                    <td style="height: 21px; width: 85px;"
                                        description 
                                    </td> 
                                     <td style="height: 21px; width: 85px;"
                                        Cat 
                                    </td> 
                                    <td style="height: 21px; width: 75px;"
                                        File 
                                    </td> 
                                    <td style="height: 21px; width: 75px;"
                                        Flier 
                                    </td>                                 
                                </tr> 
                            </table> 
                        </HeaderTemplate> 
                        <ItemTemplate> 
                            <table> 
                                <tr> 
                                    <td style="width: 144px; height: 21px"
                                        <%#Eval("id")%> 
                                    </td> 
                                    <td style="width: 198px; height: 21px"
                                        <%#Eval("datecreated")%> 
                                    </td> 
                                    <td style="height: 21px; width: 85px;"
                                        <%#Eval("description")%> 
                                    </td> 
                                    <td style="height: 21px; width: 85px;"
                                        <%#Eval("cat")%> 
                                    </td> 
                                     <td style="height: 21px; width: 75px;"
                                        <target="_blank" href="../uploads/<%# Eval("file") %>"
                                            <asp:Image runat="server" ID="Image1" AlternateText="Click here to open" 
                                                ImageUrl='../userimages/video.jpg' Style="border-width: 0px; height: 50px; Width: 50px;" /> 
                                    </td> 
                                     
                                    <td style="height: 21px; width: 75px;"
                                        <target="_blank" href="../uploads/<%# Eval("flier") %>"
                                            <asp:Image runat="server" ID="ImageThumbnail" AlternateText="Click here to open" 
                                                ImageUrl='../userimages/pdf.gif' Style="border-width: 0px; height: 50px; Width: 50px;" /> 
                                    </td> 
                                </tr> 
                            </table> 
                        </ItemTemplate> 
                        <ItemStyle HorizontalAlign="Left" /> 
                    </telerik:GridTemplateColumn> 
                </Columns> 
                <EditFormSettings EditFormType="Template"
                    <FormTemplate> 
                        <table> 
                            <tr> 
                                <td> 
                                    <table> 
                                        <tr> 
                                            <td style="width: 14px"
                                            </td> 
                                            <td> 
                                                ID:&nbsp;</td> 
                                            <td> 
                                                <asp:Label ID="lblid" runat="server" Text='<%# Eval("ID") %>'></asp:Label></td
                                            <td style="width: 19px"
                                            </td> 
                                        </tr> 
                                        
                                        <tr> 
                                            <td style="width: 14px"
                                            </td> 
                                            <td> 
                                                Date: &nbsp; &nbsp; &nbsp;&nbsp;</td> 
                                            <td> 
                                                <asp:TextBox ID="txtdate" Text='<%# Eval("datecreated") %>' runat="server"></asp:TextBox></td
                                            <td style="width: 19px"
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td style="width: 14px"
                                            </td> 
                                            <td> 
                                                Description : &nbsp; &nbsp; 
                                            </td> 
                                            <td> 
                                                <asp:TextBox ID="txtdescription" Text='<%# Eval("description") %>' runat="server" 
                                                    Height="150px" TextMode="MultiLine" Width="400px"></asp:TextBox></td
                                            <td style="width: 19px"
                                            </td> 
                                        </tr> 
                                         
                                        <tr> 
                                            <td style="width: 14px"
                                            </td> 
                                            <td> 
                                                Category : &nbsp; &nbsp; 
                                            </td> 
                                            <td> 
                                                <telerik:RadComboBox ID="DropDownList1" runat="server" SelectedValue='<%# Eval("Cat") %>' Skin="Vista" > 
                                                       <Items> 
                            <telerik:RadComboBoxItem Text="adultsermons" Value="adultsermons" /> 
                            <telerik:RadComboBoxItem Text="childsermons" Value="childsermons" /> 
                            <telerik:RadComboBoxItem Text="teensermons" Value="teensermons" Selected="true" /> 
                        </Items>      
                                                </telerik:RadComboBox>                                         
                                                     
                                         </td> 
                                            <td style="width: 19px"
                                            </td> 
                                        </tr> 
                                         
                                        
                                         <tr> 
                                            <td style="width: 14px"
                                            </td> 
                                            <td> 
                                                Flier:</td> 
                                            <td> 
                                              <telerik:radupload id="RadUpload2" runat="server" skin="Web20" initialfileinputscount="1" 
                                    maxfileinputscount="1" controlobjectsvisibility="None" maxfilesize="1000000"  
                                    /> 
                                           
                                            </td> 
                                            <td style="width: 19px"
                                            </td> 
                                        </tr> 
                                         <tr> 
                                            <td style="width: 14px"
                                            </td> 
                                            <td> 
                                                File:</td> 
                                            <td> 
                                              <telerik:radupload id="RadUpload1" runat="server" skin="Web20" initialfileinputscount="1" 
                                    maxfileinputscount="1" controlobjectsvisibility="None" maxfilesize="1000000" 
                                   /> 
                                            
                                           <telerik:radprogressmanager id="Radprogressmanager1" skin="Web20" runat="server" /> 
                <telerik:radprogressarea id="RadProgressArea1" skin="Web20" runat="server"></telerik:radprogressarea> 
                                            </td> 
                                            <td style="width: 19px"
                                            </td> 
                                        </tr> 
                                    </table> 
                                      
                                </td> 
                            </tr> 
                        </table> 
                          <asp:Button ID="btnUpdate" Text='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "Insert", "Update") %>' runat="server" CommandName='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "PerformInsert", "Update")%>' /> 
                              <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel" /> 
                    </FormTemplate> 
     
    <PopUpSettings ScrollBars="None"></PopUpSettings> 
                </EditFormSettings> 
                <ExpandCollapseColumn Resizable="False" Visible="False"
                    <HeaderStyle Width="20px" /> 
                </ExpandCollapseColumn> 
                <RowIndicatorColumn Visible="False"
                    <HeaderStyle Width="20px" /> 
                </RowIndicatorColumn> 
            </MasterTableView> 
             <ExportSettings> 
                 <Pdf PageBottomMargin="" PageFooterMargin="" PageHeaderMargin="" PageHeight="11in" 
                     PageLeftMargin="" PageRightMargin="" PageTopMargin="" PageWidth="8.5in" /> 
             </ExportSettings> 
             </telerik:RadGrid> 
             
        <asp:AccessDataSource ID="AccessDataSource1" runat="server"  
            DataFile="~/App_Data/website.mdb" SelectCommand="SELECT * FROM [sermons]"
        </asp:AccessDataSource> 
          
    </asp:Content> 

  2. Adam
    Adam avatar
    7 posts
    Member since:
    Apr 2007

    Posted 05 Sep 2008 Link to this post

    the error i get is

    ex = {"Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"}
  3. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 08 Sep 2008 Link to this post

    Hi Adam,

    Please download the latest version (Q2 SP1 - 2008.2.826) from your Client.Net account and give it a try.

    Regards,
    Veskoni
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  4. Adam
    Adam avatar
    7 posts
    Member since:
    Apr 2007

    Posted 09 Sep 2008 Link to this post

    i did change it in the project and publish it to the server, but the error still pops up.

    Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

    I did verify that the server has the new dll inside the bin folder of the application.

    the files that i uploaded to test is a simple .mp3 file a .mov file

    All flat text files seem to work fine.

  5. Adam
    Adam avatar
    7 posts
    Member since:
    Apr 2007

    Posted 10 Sep 2008 Link to this post

    here is a sample project

    www.simpweb.com/sample.rar

    I removed the dll's for ya.
  6. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 12 Sep 2008 Link to this post

    Hi Adam,

    Thank you for the provided project.

    It seems that in this case the UploadedFiles collection is empty.
    We will check this, but in the meantime I suggest that you use the following:

    RadGrid1_UpdateCommand:

    filename = UploadedFile.FromHttpPostedFile(Request.Files(0))
    and
    filename = UploadedFile.FromHttpPostedFile(Request.Files(1))

    to get the first and second uploaded file.

    Sincerely yours,
    Veskoni
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top