Ultimately, what I would like to do is upload files directly into the database, so I updated this question with the code I’m using to write to the database.
I am developing a module in DotNetNuke using Telerik controls. I need to upload files to the server in the user interface, so I am using the RadUpload control and the RadProgressArea/RadProgressManager.
Here is my ASP:
<telerik:RadUpload ID="RadUpload1" runat="server" ControlObjectsVisibility="CheckBoxes, RemoveButtons, ClearButtons"
AllowedFileExtensions=".doc,.docx,.pdf,.tiff,.gif,.jpg,.jpeg,.xls,.xlsx" MaxFileInputsCount="2"
MaxFileSize="10000000" InitialFileInputsCount="2">
</telerik:RadUpload>
<br />
<asp:Button ID="UploadButton" runat="server" Text="Upload File(s)" />
<telerik:RadProgressArea ID="RadProgressArea1" runat="server" ProgressIndicators="TotalProgressBar, TotalProgress, RequestSize, FilesCountBar, FilesCount, SelectedFilesCount, CurrentFileName, TimeElapsed, TimeEstimated, TransferSpeed">
</telerik:RadProgressArea>
<br />
<telerik:RadProgressManager ID="RadProgressManager1" Runat="server" />
And here is my VB:
Protected Sub UploadButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles UploadButton.Click
If RadUpload1.UploadedFiles.Count > 0 Then
System.Threading.Thread.Sleep(3000)
End If
For Each file As UploadedFile In RadUpload1.UploadedFiles
Dim bytes(file.ContentLength - 1) As Byte
file.InputStream.Read(bytes, 0, file.ContentLength)
Try
' Create the sales order in the database on page load so that the salesorderid is unique
Dim connection As String = ConfigurationManager.ConnectionStrings("SiteSqlServer").ConnectionString
Dim con As New SqlConnection(connection)
Dim cmd As New SqlCommand("INSERT INTO TTC_UploadedFiles ([Name], [Size], [Content]) VALUES (?, ?, ?)", con)
cmd.Parameters.AddWithValue("@Name", file.GetName())
cmd.Parameters.AddWithValue("@Size", bytes.Length)
cmd.Parameters.AddWithValue("@Content", bytes)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
Catch ex As Exception
Label1.Text = ex.ToString
End Try
Next
End Sub
When I hit the button, it does a postback to the page, but the files do not get uploaded. I tried using the autoupload functions and specifying pysical and virtual paths but that didn’t work. I did it exactly like they said. I manually registered the controls in my web.config, then removed them and used the auto-register feature to re-register thinking maybe I did something wrong, but I’m still at a loss.
Here’s where I spent the last couple hours:
[Upload Overview][3]
[Files are not uploaded][4]
Can someone help me get this upload control and progress indicator working?
This is not direct related to your question. I use AsyncUpload, which can select muliple files at once, and upload files to database. The following is the sample code. I strip out the validation codes for the sake of simplicity.
Edit: In web.config, depending on what IIS you are using.