Use of AsyncUpload inside RadGrid

7 posts, 0 answers
  1. Fawad
    Fawad avatar
    20 posts
    Member since:
    Nov 2014

    Posted 15 Nov 2014 Link to this post

    Dear All,
    Can someone please help me with AsyncUpload control inside RadGrid since I am really new with Telerik controls.

    I have a DB table with column names as:

    RecordID          Name          AttachmentPath
    1                       Name1        ~/Attachments/File123_1.pdf
    2                       Name2        ~/Attachments/File125_2.pdf

    Below are what I did:

    1. Inserted RadGrid with its default functionality of Inserting, Editing, and Deleting. (Works Perfect)
    2. Inserted AsyncUpload control inside RadGrid for uploading files. (Works Perfect)

    <telerik:GridTemplateColumn>
        <EditItemTemplate>
            <telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server" TargetFolder="~/Attachments"
        OnFileUploaded="RadAsyncUpload1_FileUploaded1">
            </telerik:RadAsyncUpload>
        </EditItemTemplate>
    </telerik:GridTemplateColumn>

    3. Fired the OnFileUploaded event to upload control in a path. (Works Perfect)

    protected void RadAsyncUpload1_FileUploaded1(object sender, FileUploadedEventArgs e)
    {
        string rootPath = "~/Attachments/";
     
        string path = Server.MapPath(createSubFolder(rootPath));
        e.File.SaveAs(path + e.File.GetName());
    }

    Below are what I want:

    1. While adding new record & uploading file with it, the file should be renamed with the table Record ID of RadGrid as OrignalFileName + "_" + RecordID
    2. The FileName from point#1 should be stored in AttachmentPath (DB Column name).
    3. While editing a selected record from RadGrid, I should be also able to edit associated file such as delete the file, etc.

    Point to be noted, I want only one file to be associated/attached per record.


    Thanks In Advance,

    Fawad Surosh

  2. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 20 Nov 2014 Link to this post

    Hello Fawad,

    In order to modify the file name of a certain UploadedFIle, you could use its SaveAs method and concatenate its name, regarding the original one and the RecordID. Pleas refer to the following forum threads where a simple examples for achieving this functionality are given:
    As for the deletion of the file - this should be custom implemented. For example, you could list the uploaded files names with a delete buttons next to them. Once the user deletes (or edits) the uploaded files names, then at the Update click you should manually perform the needed actions - such as deleting the Item and update the records for currently edited row in your database.

    Regards,
    Nencho
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Fawad
    Fawad avatar
    20 posts
    Member since:
    Nov 2014

    Posted 20 Nov 2014 in reply to Nencho Link to this post

    Hello Nencho,

    Thank you for the response.
    My table Id is "Is Identity enabled" which is not going to be visible until a record is inserted.

    I came around with solving the other stuffs but two concerns that I am still stack with:

    1) On FileUploaded event, I cannot get the table Id of the table which makes sense since the record is not still inserted into the database so how can i get the table Id concatenated with the file name after the record is posted into the database.
    2) I want the deletion of file to be done automatically when a record is being deleted.



  5. SANJAY
    SANJAY avatar
    61 posts
    Member since:
    Jun 2012

    Posted 20 Nov 2014 in reply to Fawad Link to this post

    Hi Fawad

    1) You can save file with unique name. eg you can generate the guid string and save file with that name. Once the record is inserted and you have the record ID, you might need to do two actions
         a) Rename the file with new name
         b) Update the field value with new name of the file

    2) You would have to write a small code which executes after you call the procedure to delete the record. This would delete the file from the server

    Regards



    Sanjay Gupta
  6. Fawad
    Fawad avatar
    20 posts
    Member since:
    Nov 2014

    Posted 21 Nov 2014 in reply to SANJAY Link to this post

    Hi Sanjay,

    I am stuck to this issue since last 5 days. I will really appreciate if you can send me a simple solution having only three columns such as ID (DB Identity Yes), Name, ImagePath in which please apply these two functions (updating the image names with the record id, and deleting the image after record is being deleted). Please don't mind because I am really new to this production.

    Thank you in advance,

    M. Fawad Surosh
  7. SANJAY
    SANJAY avatar
    61 posts
    Member since:
    Jun 2012

    Posted 22 Nov 2014 in reply to Fawad Link to this post

    Hi Fawad

    You can download a test module for the same from
    http://www.thetaskmate.com/app/telerik/asyntest.zip

    1) The application is in vb.net . I guess you are writing in C#. I am more familliar with vb.net
    2) I have used xml file as datasource for the test module but I think I have replicated your requirement

    3) Recommedation : Donot define TargetFolder. I you insist to define the same I will write code with target folder
    4) In Need datasource a blank record is created and saved as xml file
    5) In Radgrid_Insertcommand :
        a) The file is save in the temporary folder by Rad Control
        b) Code saves the same in tmp folder
        c) When the record is saved the id generated
        d) the file is moved with new name

    6) I have not included code for delete


    Regards


    Sanjay Gupta
  8. SANJAY
    SANJAY avatar
    61 posts
    Member since:
    Jun 2012

    Posted 22 Nov 2014 in reply to SANJAY Link to this post

    Hi Fawad

    Check the page
    tms-grd.aspx     

    Regards


    Sanjay
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017