Using radupload twice on one page

Thread is closed for posting
5 posts, 0 answers
  1. Jay
    Jay avatar
    17 posts
    Member since:
    Jun 2007

    Posted 22 Oct 2008 Link to this post

    Hi

    I am trying to use the radupload device twice on the same page.
    I have two seperate database fields for holding the names of a standard and technical graphic.

    The graphics have two different folder areas on the server.

    Is it possible to load the radupload twice on the page with the select ability limited to 1 file per control and succesfully insert the field infornation using a stored procedure?.

    I have supplied my standard code for 1 radupload in the hope that you can see my potential issue pulling from two seperate radupload controls.

    Code -----------------

     If RadUpload1.UploadedFiles.Count = 0 Then
                'Ceate SQL Connection & Open it
                Dim objConn As New SqlConnection("Data Source=")
                objConn.Open()
              
                'Create a command object for the stored proc
                Dim objCmd As New SqlCommand("a_", objConn)
                objCmd.CommandType = Data.CommandType.StoredProcedure
                objCmd.CommandText = "a_"

        

                objCmd.Parameters.Add(New SqlParameter("@headline", Data.SqlDbType.VarChar, 255))
                objCmd.Parameters("@headline").Value = txtheadline.Text
           
                objCmd.Parameters.Add(New SqlParameter("@Name", Data.SqlDbType.VarChar, 100))
                objCmd.Parameters("@Name").Value = "none.gif"
        
               
                objCmd.ExecuteNonQuery()
                objConn.Close()
                   
                Response.Redirect("page.aspx")
            Else
                For Each f As UploadedFile In RadUpload1.UploadedFiles
                    f.SaveAs("C:\folder\" & f.GetName, True)
                Next
           
                For Each file As UploadedFile In RadUpload1.UploadedFiles

               
                    Dim bytes(file.InputStream.Length) As Byte
                    file.InputStream.Read(bytes, 0, file.InputStream.Length)
               
                    'Ceate SQL Connection & Open it
                    Dim objConn As New SqlConnection("Data Source=")
                    objConn.Open()
              
                    'Create a command object for the stored proc
                    Dim objCmd As New SqlCommand("a_", objConn)
                    objCmd.CommandType = Data.CommandType.StoredProcedure
                    objCmd.CommandText = "a_"

        

                    objCmd.Parameters.Add(New SqlParameter("@headline", Data.SqlDbType.VarChar, 255))
                    objCmd.Parameters("@headline").Value = txtheadline.Text

           
                    objCmd.Parameters.Add(New SqlParameter("@Name", Data.SqlDbType.VarChar, 100))
                    objCmd.Parameters("@Name").Value = file.GetName
        
               
                    objCmd.ExecuteNonQuery()
                    objConn.Close()
                   
                    Response.Redirect("page.aspx")
                Next
            End If

    ----------------------------------

    Thanks in advance

    J

  2. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 24 Oct 2008 Link to this post

    Hello Jay,

    Yes, you can have two RadUploads on the page. Upon submitting the form you can insert the appropriate record in the data base for each Upload which has a file in it. If no files are selected in neither of the controls, then you can redirect the page.

    Isn't this what are you trying to achieve? If not, please elaborate more on your goal.

    Best wishes,
    Simon
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Jay
    Jay avatar
    17 posts
    Member since:
    Jun 2007

    Posted 27 Oct 2008 Link to this post

    Hi,

    Does an example exist that shows how to use getname and the progress area in this situation?

    I am not sure how to use getname for two seperate raduploads on Insert and how this affects the insert parameter:

    d.Parameters.Add(New SqlParameter("@Name", Data.SqlDbType.VarChar, 100))
                    objCmd.Parameters("@Name").Value = file.GetName

    Thanks
    J

  4. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 29 Oct 2008 Link to this post

    Hi Jay,

    One of each - RadProgressManager and RadProgressArea - is sufficient enough. Progress will be shown for both RadUploads on the page.

    As for the code, you can put it in a separate routine with one argument of type RadUpload and call it for both controls upon form submission. The SQL will be executed twice for each Upload. Please consider the code below:

    Protected Sub Button1_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles Button1.Click 
        ProcessFiles(RadUpload1) 
        ProcessFiles(RadUpload2) 
    End Sub 
     
    Private Sub ProcessFiles(ByVal upload As RadUpload) 
        If upload.UploadedFiles.Count = 0 Then 
            'Ceate SQL Connection & Open it 
            Dim objConn As New SqlConnection("Data Source="
            objConn.Open() 
     
            'Create a command object for the stored proc 
            Dim objCmd As New SqlCommand("a_", objConn) 
            objCmd.CommandType = Data.CommandType.StoredProcedure 
            objCmd.CommandText = "a_" 
     
     
     
            objCmd.Parameters.Add(New SqlParameter("@headline", Data.SqlDbType.VarChar, 255)) 
            objCmd.Parameters("@headline").Value = txtheadline.Text 
     
            objCmd.Parameters.Add(New SqlParameter("@Name", Data.SqlDbType.VarChar, 100)) 
            objCmd.Parameters("@Name").Value = "none.gif" 
     
     
            objCmd.ExecuteNonQuery() 
            objConn.Close() 
     
            Response.Redirect("page.aspx"
        Else 
            For Each f As UploadedFile In upload.UploadedFiles 
                f.SaveAs("C:\folder\" & f.GetName, True
            Next 
     
            For Each file As UploadedFile In upload.UploadedFiles 
     
     
                Dim bytes(file.InputStream.Length) As Byte 
                file.InputStream.Read(bytes, 0, file.InputStream.Length) 
     
                'Ceate SQL Connection & Open it 
                Dim objConn As New SqlConnection("Data Source="
                objConn.Open() 
     
                'Create a command object for the stored proc 
                Dim objCmd As New SqlCommand("a_", objConn) 
                objCmd.CommandType = Data.CommandType.StoredProcedure 
                objCmd.CommandText = "a_" 
     
     
     
                objCmd.Parameters.Add(New SqlParameter("@headline", Data.SqlDbType.VarChar, 255)) 
                objCmd.Parameters("@headline").Value = txtheadline.Text 
     
     
                objCmd.Parameters.Add(New SqlParameter("@Name", Data.SqlDbType.VarChar, 100)) 
                objCmd.Parameters("@Name").Value = file.GetName 
     
     
                objCmd.ExecuteNonQuery() 
                objConn.Close() 
     
                Response.Redirect("page.aspx"
            Next 
        End If 
    End Sub 

    I hope this helps.

    Greetings,
    Simon
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Jay
    Jay avatar
    17 posts
    Member since:
    Jun 2007

    Posted 04 Nov 2008 Link to this post

    Brilliant,

    Thank you very much.

    J
Back to Top