AsyncUpload to Database

12 posts, 0 answers
  1. Graham Till
    Graham Till avatar
    1 posts
    Member since:
    Jan 2010

    Posted 06 Oct 2010 Link to this post

    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.
  2. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 posts

    Posted 07 Oct 2010 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Roberto Lo Baido
    Roberto Lo Baido avatar
    1 posts
    Member since:
    Feb 2010

    Posted 17 Dec 2010 Link to this post

    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.
  5. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 posts

    Posted 22 Dec 2010 Link to this post

    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.
  6. Matthew
    Matthew avatar
    51 posts
    Member since:
    Oct 2012

    Posted 01 Jul 2013 Link to this post

    Is there an updated demo? The link no longer works.
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 02 Jul 2013 Link to this post

    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.
  8. Jamie Ferrara
    Jamie Ferrara avatar
    3 posts
    Member since:
    Nov 2004

    Posted 05 Jul 2013 Link to this post

    The link to the demo appears to be dead.
  9. Griffin
    Griffin avatar
    5 posts
    Member since:
    Jul 2009

    Posted 15 Jul 2013 Link to this post

    Current link to the previously mentioned demo: AsyncUpload - Custom Http Handler
  10. Ric
    Ric avatar
    5 posts
    Member since:
    Aug 2013

    Posted 17 Oct 2013 Link to this post

    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.
  11. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 22 Oct 2013 Link to this post

    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.
  12. Artur
    Artur avatar
    6 posts
    Member since:
    Apr 2016

    Posted 12 May Link to this post

    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

  13. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 13 May Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017