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

Persist Uploaded Files with autogenerated PerformInsertButton on Radgrid

1 Answer 56 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 30 May 2013, 03:40 PM
Perhaps someone can help with this.

I'm currently trying to upload some files to be inserted into a db table.  The files are linked to a parent record id in a different table.

Appointment <= (Many) Attachments

So one appointment can have many attachments.

Within a radgrid the user enters details for a new appointment and can then upload attachment files.  The attachment files are to be inserted  with the new appointment record id.

The problem I have found is that the File Upload triggers before the insert of the new record (which is inserted using an entitydatasource).

My thinking is that if I can capture the insert of the record and use PostbackTriggers, I can insert the new appointment, capture the newly generated appointment id, then trigger the upload of the files which will now be able to be inserted with the appointment id.

If anyone could point me to an example where you can capture the PerformInsertButton button click on the insert form and then trigger the upload in this order it would be considerable help at the moment.

The nearest example code I can find for what I want to do seems to be Scotts code in this post :

http://www.telerik.com/community/forums/aspnet-ajax/async-upload/retain-uploaded-files-for-display-after-postback.aspx

Thanks.

1 Answer, 1 is accepted

Sort by
0
Hristo Valyavicharski
Telerik team
answered on 04 Jun 2013, 12:33 PM
Hi Michael,

Once the ItemCommand event is fired, you could use FindControl() to get instance of RadAsyncUpload from the Inserted form. Then get and save file you need from the UploadedFiles collection:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.PerformInsertCommandName)
    {
        GridEditFormItem insertItem = (GridEditFormItem)e.Item;          
        RadAsyncUpload upload =(RadAsyncUpload) insertItem.FindControl("RadAsyncUpload1");
        string path = Server.MapPath("~/Uploads/");
        string fileName = upload.UploadedFiles[0].FileName;
        upload.UploadedFiles[0].SaveAs(path + fileName);
    }
}

Sample project is attached.

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 their blog feed now.
Tags
AsyncUpload
Asked by
Michael
Top achievements
Rank 1
Answers by
Hristo Valyavicharski
Telerik team
Share this question
or