Copy and download file when deploying application

This guide demonstrates how to copy and download file when deploying application.

Source Code

Step by step

1. Create new application with .NET server-side project.

2. Add desired file(s) in project.csproj\project.vbproj

    <None Include="ProductSales.pdf" CopyToPublishDirectory="Always" />

3. Execute custom method similar to this article to download the file.

import { Component, Injector } from '@angular/core';
import { MainPageGenerated } from './main-page-generated.component';

// Import HttpClient and HttpParams which are needed to make HTTP calls.
import { HttpClient, HttpParams } from '@angular/common/http';
// Import the environment to get the server URL
import { environment } from '../../environments/environment';

  selector: 'main-page',
  templateUrl: './main-page.component.html'
export class MainPageComponent extends MainPageGenerated {
  constructor(injector: Injector, private http: HttpClient) {

  getFile(fileName: string) {
    // Extract the server URL
    const url = environment.sample.replace(/odata.*/, '');

    return this.http
      // Request the GetFile action method
      .get(`${url}api/custommethod/getfile`, {
        responseType: 'blob',
        params: new HttpParams().set('fileName', fileName)
      .map((value: Blob, index: number) => {
        // Force browser to show downloaded content as file
        if (navigator.msSaveBlob) {
          navigator.msSaveBlob(value, fileName);
        } else {
          const link = document.createElement("a");
          if ( !== undefined) {
            link.setAttribute("href", URL.createObjectURL(value));
            link.setAttribute("download", fileName);
   = 'hidden';

using System.IO;
using Microsoft.AspNetCore.Mvc;

namespace Sample.Controllers
    public class CustomMethodController : Controller
        public IActionResult GetFile(string fileName)
            if (System.IO.File.Exists(fileName))
                return File(System.IO.File.ReadAllBytes(fileName), contentType: "application/pdf");
            return NotFound();
Imports System.IO
Imports Microsoft.AspNetCore.Mvc

Namespace Sample.Controllers
    Public Class CustomMethodController
        Inherits Controller

        Public Function GetFile(ByVal fileName As String) As IActionResult
            If System.IO.File.Exists(fileName) Then
                Return File(System.IO.File.ReadAllBytes(fileName), contentType:="application/pdf")
            End If

            Return NotFound()
        End Function
    End Class
End Namespace

4. Deploy the application to IIS and download file.

Get Radzen