Simple File Attachment

4 posts, 0 answers
  1. John
    John avatar
    3 posts
    Member since:
    Jun 2017

    Posted 04 Dec 2017 Link to this post

    I am new to the Telerik controls, and I am having a difficult time achieving what I would think would be a fairly simple task.

    I have a radgrid with it's edit form type set to "template".  I would like to add a simple "file attachment" feature to the form, so that someone can attach a file when editing the record, and be able so see/open the attachments when viewing the record.  Nothing fancy, just basic file attachment functionality. I was hoping there would be a basic "file attachment" type of control where I can just drop it on the form and tell it "here is my field to store the file, and here is the ID field (or some field) from the RadGrid datasource to use as a key" and it just works, but unless I am overlooking something I don't see it.  Even as I am writing this post I notice this message board has a simple "Attach files" option at the bottom that I assume works like I what I want.

    I have tried in vain to search through the forums and look at all the demo's, but I think I am only confusing myself. I have looked at the demos for the RadAsynchUpload control which seems close to what I need, but the demos don't seem to be set up with a radgrid edit template in use. They also seem to involve a fair amount of customised coding, which I was hoping to avoid.  I also looked into the attachment grid column type, but I couldn;t get that to work either. 

    Can anyone provide me a clear/simple demo (VB.net) that shows how to achieve what I need?  I would prefer to store the files (they will be small files, and only one file per record) in the SQL database, but could store them in a folder if that makes it easier.

    Thanks.

  2. Rumen
    Admin
    Rumen avatar
    13547 posts

    Posted 05 Dec 2017 Link to this post

    Hi John,

    There is an integration demo for RadAsyncUpload in an EditItemTemplate of RadGrid, which you can use as a base with your implementation: AsyncUpload - Integration with Ajaxified RadGrid. The demo comes with VB.NET version which you can see in the code viewer or load in Visual Studio if you have the demo app installed on your machine.

    In order to save the uploaded files into the database you could use the InputStream property to access the content of the uploaded files:

    Dim file As UploadedFile = radAsyncUpload.UploadedFiles(0)
    Dim fileData As Byte() = New Byte(file.InputStream.Length - 1) {}
    file.InputStream.Read(fileData, 0, CInt(file.InputStream.Length))
    cmd.Parameters.Add("@Data", SqlDbType.Image)
    cmd.Parameters("@Data").Value = fileData


    Best regards,
    Rumen
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. John
    John avatar
    3 posts
    Member since:
    Jun 2017

    Posted 05 Dec 2017 in reply to Rumen Link to this post

    Thank you for the reply.  I am not sure if this addresses my needs though (this is part of my confusion).  I looked at that demo you linked to already, and it doe snot seem to match my situation.  

    In my application I have the EditFormSettings section defined like this "<EditFormSettings EditFormType="Template">", followed by a FormTemplate section that contains all of the controls.  The demo does not have any of this.  The VB code behind for the demo is also a bit confusing because it contains a lot of code across multiple subroutines that are there for the demo as a whole, and I have a bit of a hard time identifying exactly which bits are needed to make the RadAsynchUpload control work vs all the code I don't really need for my case.  Having to weed through every line of code and try to figure out which ones I need to make the control work, and which I can ignore because they are specific to the demo is time consuming, as well as confusing, since I don't really know for sure.

    What I would like ideally would be some straightforward instructions along the lines of "drop the uploader control into the template, then modify the RadGrid's Item_Command subrotuine to include the code to do x/y/z, then add the AsyncUpload1_FileUploaded subroutine.....", etc.  Just some basic steps to add the uploader to the form and get it working.

    Thanks

  4. Rumen
    Admin
    Rumen avatar
    13547 posts

    Posted 08 Dec 2017 Link to this post

    Hi John,

    You can easily isolate the demo code into a standalone application and removing all demo app dependencies by following the instructions in this article: How to Isolate This Demo as a Standalone Application (Removing the Live Demos Site Dependencies). If you are not sure about the use of some line in the code, comment it out and debug it to see whether it is used or not.

    You can also download the demo app locally and run it in Visual Studio using the provided under the Downloads section of your account installation: Telerik_UI_for_ASP.NET_AJAX_2017_3_913_Demos_Dev.msi.

    As to the upload itself to a databased via RadAsyncUpload handler, please see the following resources: 
    https://www.telerik.com/forums/asyncupload-to-database
    http://demos.telerik.com/aspnet-ajax/asyncupload/examples/imageuploader/defaultcs.aspx

    Regards,
    Rumen
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top