# Display File Location for Each Uploaded File

## Environment

<table>
 <tr>
  <td>Product</td>
  <td>Telerik UI for ASP.NET MVC Upload</td>
 </tr>
 <tr>
  <td>Progress Telerik UI for ASP.NET MVC version</td>
  <td>Created with the 2023.3.1114 version</td>
 </tr>
</table>

## Description

How can I display the location of the uploaded file as a link within the Upload component?

## Solution

1. Define an Upload component in [asynchronous mode](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/editors/upload/modes-of-operation#asynchronous-mode).
2. Use the [`TemplateId`](https://docs.telerik.com/aspnet-mvc/api/kendo.mvc.ui.fluent/uploadbuilder#templateidsystemstring) option to define a template for rendering the files in the file list.
3. Update the `Save` Action method to return the file location of the uploaded file.
4. Subscribe to the [`Success`](https://docs.telerik.com/aspnet-mvc/api/kendo.mvc.ui.fluent/uploadeventbuilder#successsystemstring) event to intercept the received file location from the server. Select the anchor tag within the file template with jQuery and update the `href` attribute with the respective file location.

```Razor HtmlHelper
    @(Html.Kendo().Upload()
        .Name("files")
        .TemplateId("fileTemplate")
        .Async(a => a
            .Save("Async_Save", "Home")
            .Remove("Remove", "Home")
            .AutoUpload(true)
        )
        .Events(ev => ev.Success("onSuccess"))
    )

    <script id="fileTemplate" type="text/x-kendo-template">
        <span class="k-progress"></span>
        <span class="k-file-group-wrapper">
            <span class="k-file-group k-icon k-i-file-image"></span>
            <span class="k-file-state"></span>
        </span>
        <span class="k-file-name-size-wrapper">
            <span class="k-file-name"><a href="" target="_blank">#=data.name#</a></span>
        </span>
        <strong class="k-upload-status">
            <button type="button" class="k-button k-icon-button k-button-flat k-upload-action"><span class="k-button-icon k-icon k-i-close k-i-x" title="Remove"></span>
            </button>
        </strong>
    </script>
```

```JS scripts
    <script>
        function onSuccess(e) {
            var uploadedFileName = e.files[0].name;
            var fileLocation = e.response.location;
            var fileLocationLinks = $(".k-file-name a");
            $.each(fileLocationLinks, function () {
                if ($(this).text() == uploadedFileName) {
                    $(this).attr("href", fileLocation);
                }
            });
        }
    </script>
```

```C# Controller
    public ActionResult Async_Save(IEnumerable<HttpPostedFileBase> files)
    {
        string filesLocation = null;
        if (files != null)
        {
            foreach (var file in files)
            {
                var fileName = Path.GetFileName(file.FileName);
                var physicalPath = Path.Combine(Server.MapPath("~/App_Data"), fileName);
                filesLocation = physicalPath;
                file.SaveAs(physicalPath);
            }
        }
        return Json(new { location = filesLocation }, JsonRequestBehavior.AllowGet);
    }
```

## More ASP.NET MVC Upload Resources

* [ASP.NET MVC Upload Documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/editors/upload/overview)

* [ASP.NET MVC Upload Demos](https://demos.telerik.com/aspnet-mvc/upload)

* [ASP.NET MVC Upload Product Page](https://www.telerik.com/aspnet-mvc/upload)

* [Telerik UI for ASP.NET MVC Video Onboarding Course (Free for trial users and license holders)](https://www.telerik.com/aspnet-mvc/documentation/getting-started/video-onboarding)

* [Telerik UI for ASP.NET MVC Forums](https://www.telerik.com/forums/aspnet-mvc)

## See Also

* [Client-Side API Reference of the Upload for ASP.NET MVC](https://docs.telerik.com/kendo-ui/api/ui/upload)

* [Server-Side API Reference of the Upload for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/api/upload)

* [Telerik UI for ASP.NET MVC Breaking Changes](https://www.telerik.com/aspnet-mvc/documentation/backwards-compatibility/2023-backwards-compatibility)

* [Telerik UI for ASP.NET MVC Knowledge Base](https://docs.telerik.com/aspnet-mvc/knowledge-base)
