This is a migrated thread and some comments may be shown as answers.

Using radupload twice on one page

4 Answers 76 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Jay
Top achievements
Rank 1
Jay asked on 22 Oct 2008, 04:46 PM
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

4 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 24 Oct 2008, 03:09 PM
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.
0
Jay
Top achievements
Rank 1
answered on 27 Oct 2008, 08:18 AM
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

0
Simon
Telerik team
answered on 29 Oct 2008, 04:18 PM
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.
0
Jay
Top achievements
Rank 1
answered on 04 Nov 2008, 02:00 PM
Brilliant,

Thank you very much.

J
Tags
Upload (Obsolete)
Asked by
Jay
Top achievements
Rank 1
Answers by
Simon
Telerik team
Jay
Top achievements
Rank 1
Share this question
or