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

Open uploaded file.

1 Answer 167 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Jane
Top achievements
Rank 1
Jane asked on 08 Aug 2013, 06:46 PM
Hi Telerik

I am using asyncupload control to upload client files. On selecting files and uploading the names will appear on the control. So at this point I have a requirement to open the uploaded file by clicking the filename or add a button such as "View File". Please provide your valuable support.

Thanks and Regards
Jane.

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 09 Aug 2013, 06:41 AM
Hi Jane,

Please have a look into the following code I tried to open the uploaded image in a new browser tab on clicking the file name rendered below the file input. Since I am reading the file from the final upload destination, I have implemented a custom handler to upload the file on the server once they are selected.

ASPX:
<telerik:RadAsyncUpload runat="server" ID="RadAsyncUpload1" HttpHandlerUrl="~/RadAsyncUpload/Preview/Handler.ashx"
    MultipleFileSelection="Automatic" OnClientFileUploaded="onClientFileUploaded">
</telerik:RadAsyncUpload>

JavaScript:
<script type="text/javascript">
    //Here you can specify the corresponding the target upload path
    var path = "http://localhost:49535/Telerik_Project/RadAsyncUpload/Uploads/";
    var $ = $telerik.$;
    function onClientFileUploaded(sender, args) {
        var row = args.get_row();
        var span = $(row).find(".ruFileWrap .ruUploadProgress");
        span.text("").append("<a target='_blank' href='" + path + args.get_fileName() + "'>" + args.get_fileName() + "</a>");
    }
</script>

C#: (HttpHandler)
public class Handler : Telerik.Web.UI.AsyncUploadHandler
{
    protected override Telerik.Web.UI.IAsyncUploadResult Process(Telerik.Web.UI.UploadedFile file, HttpContext context, Telerik.Web.UI.IAsyncUploadConfiguration configuration, string tempFileName)
    {
        var path = context.Server.MapPath("Uploads");
 
        file.SaveAs(path + "\\" + file.GetName());
        return CreateDefaultUploadResult<Telerik.Web.UI.UploadedFileInfo>(file);
    }
}

Thanks,
Shinu.
Tags
AsyncUpload
Asked by
Jane
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or