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

AsyncUpload to Database

11 Answers 827 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Graham Till
Top achievements
Rank 1
Graham Till asked on 06 Oct 2010, 11:09 AM
Hi. Is there a good example anywhere of how to use the AsyncUpload control (ideally with mutiple file selection set to auto), but where the uploaded files are not just saved to the file system but are handled as a stream for the purposes of saving to a database. Many thanks in advance for you help.

11 Answers, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 07 Oct 2010, 04:50 PM | edited on 20 Jan 2023, 12:57 PM
Hi Graham Till,

I suggest that you take a look at the following demo. It demonstrates a scenario closely related to what you are trying achieve.

Greetings,
Genady Sergeev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Roberto Lo Baido
Top achievements
Rank 1
answered on 17 Dec 2010, 10:23 AM
I followed the demo and everything works so i am able to save file to database, but is it possible to avoid saving the file in the temorary Folder.
When the Process method of the handler is fired, the file has been already saved by the uploader; if it is possible i would like to have it only in memory.
0
Genady Sergeev
Telerik team
answered on 22 Dec 2010, 12:39 PM
Hello Graham Till,

The files are always buffered to the temp folder since buffering them enirely into the memory is very likely to cause serious impact on the web server. Imagine what would happen on a shared hosting, for example.

Kind regards,
Genady Sergeev
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Matthew
Top achievements
Rank 1
answered on 01 Jul 2013, 06:45 PM
Is there an updated demo? The link no longer works.
0
Shinu
Top achievements
Rank 2
answered on 02 Jul 2013, 07:31 AM
Hi Matthew,

Please have a look at the following sample code I tried to save uploaded files in database.

ASPX:
<telerik:RadAsyncUpload runat="server" ID="RadAsyncUpload1" TargetFolder="~/Images/Img/"
    AllowedFileExtensions=".jpg" MaxFileSize="57971152" MultipleFileSelection="Automatic"
    UploadedFilesRendering="BelowFileInput" OnFileUploaded="RadAsyncUpload1_FileUploaded">
</telerik:RadAsyncUpload>
<br />
<telerik:RadButton ID="RadButton1" runat="server" Text="Submit">
</telerik:RadButton>

C#:
protected void RadAsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e)
{
    Stream fileStream = e.File.InputStream;
    byte[] attachmentBytes = new byte[fileStream.Length];
    fileStream.Read(attachmentBytes, 0, Convert.ToInt32(fileStream.Length));
 
    System.Data.SqlClient.SqlConnection conn = null;
    try
    {
        try
        {
            conn = new System.Data.SqlClient.SqlConnection(
                ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
            conn.Open();
            System.Data.SqlClient.SqlCommand insertCommand =
                new System.Data.SqlClient.SqlCommand(
                "Insert into [Pictable] (msgid, pic1) Values (1, @Pic)", conn);
            insertCommand.Parameters.Add("@Pic", SqlDbType.VarBinary).Value = attachmentBytes;
            int queryResult = insertCommand.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
        }
    }
    finally
    {
        if (conn != null)
        {
            fileStream.Close();
            conn.Close();
        }
    }
}

Thanks,
Shinu.
0
Jamie Ferrara
Top achievements
Rank 1
answered on 05 Jul 2013, 09:02 PM
The link to the demo appears to be dead.
0
Griffin
Top achievements
Rank 1
answered on 15 Jul 2013, 03:53 PM
Current link to the previously mentioned demo: AsyncUpload - Custom Http Handler
0
Ric
Top achievements
Rank 1
answered on 17 Oct 2013, 06:24 PM
As far as I can see, the  AsyncUpload - Custom Http Handler demo does not work. It still requires a TempFolder. I've followed that demo to letter and it still requires the folder as an intermediate step to the database. I've tried it with DisableChunkUpload to both ways. This is an extremely frustrating exercise and hardly worth the money we've paid.
0
Hristo Valyavicharski
Telerik team
answered on 22 Oct 2013, 02:14 PM
Hi Ric,

Why do you think that the demo is not working. Its purpose is to demonstrates how to upload files into the Database? The DisableChunkUpload property specify if the file will be uploaded on chunks or at once, but it has nothing to do with the Temporary folder. However it is true that when this property is enabled the selected file will not be uploaded to the Temporary folder, it will be transfer at once to the handler with the HttpContext object. 

By design RadAsyncUpload always create a TemporaryFolder to verify if the control has write permissions to the File System. Note that the default configuration of the control uses uploading on chunking. If you cannot use the App_Data\RadUpload folder, than you can change it by setting the TargetFolder property.

If you would like such functionality that allow you to control whether the TemporaryFolder will be created or not you can submit a new feature request.

Regards,
Hristo Valyavicharski
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Artur
Top achievements
Rank 1
answered on 12 May 2016, 03:21 PM

I have a CSV file with ~200 000 records to load into a database. In my application I use Entity Framework 6.1.3 to communicate with a database. Can I still utilize the RadAsyncUpload control to simply import data into a database? Or there's another better solution for this?

Regards,

Artur

0
Hristo Valyavicharski
Telerik team
answered on 13 May 2016, 07:30 AM
Hi Artur,

AsyncUpload gives you  access to the Input Stream of the Uploaded Files, so can use this:
<telerik:RadAsyncUpload runat="server" ID="async" OnFileUploaded="async_FileUploaded"
    RenderMode="Lightweight" AllowedFileExtensions=".csv">
</telerik:RadAsyncUpload>
<telerik:RadButton runat="server" ID="btn" Text="Submit"></telerik:RadButton>
protected void async_FileUploaded(object sender, FileUploadedEventArgs e)
{
    StreamReader csvreader = new StreamReader(e.File.InputStream);
 
    while (!csvreader.EndOfStream)
    {
        var line = csvreader.ReadLine();
        var values = line.Split(';');
        System.Diagnostics.Debug.WriteLine(line);
    }
}

I hope this helps.

Regards,
Hristo Valyavicharski
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
AsyncUpload
Asked by
Graham Till
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Roberto Lo Baido
Top achievements
Rank 1
Matthew
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Jamie Ferrara
Top achievements
Rank 1
Griffin
Top achievements
Rank 1
Ric
Top achievements
Rank 1
Hristo Valyavicharski
Telerik team
Artur
Top achievements
Rank 1
Share this question
or