Table of Contents

Upload new template

Products: FastReport Cloud, FastReport Corporate Server, FastReport Publisher

One of the main features of Service solutions is storing templates, reports, and other data in the cloud. This article will describe how to upload your own template to service solution template storage.

Getting started

You will need the following tools and facilities:

  1. Know how to use API key in Service solutions.

    This article will skip over additional information on authentication and authorization.

  2. .NET SDK.

  3. C# code editor or text editor, e.g., Visual Studio Code.

  4. Report template.

    It can be generated in the free FastReport Community Designer program.

  5. Active subscription to one of the following products: FastReport Cloud, FastReport Corporate Server, or FastReport Publisher.

  6. Internet access.

Important! These guides assume that you already know how to develop your application in the C# programming language.

Note. The items above describe recommended tools.

Instruction

  1. You need to get the root folder ID of the workspace. This ID will never change, so you can save it and not have to request it each time before loading a new template.

    To request the root directory, call the method GetRootFolderAsync(string, CancellationToken).

    public async Task<string> GetTemplatesRoot(HttpClient httpClient, string subscriptionId = null)
    {
        ITemplateFoldersClient templateFoldersClient = new TemplateFoldersClient(httpClient);
    
        FileVM result = await templateFoldersClient.GetRootFolderAsync(subscriptionId);
    
        return result.Id;
    }
    

    In this example, the subscriptionId parameter specifies the workspace (subscription) ID, if it is not specified (equal to null), the default user workspace ID will be returned.

  2. To upload the necessary template, use the following method UploadFileAsync(string, TemplateCreateVM, CancellationToken).

    public async Task<string> UploadFrx(HttpClient httpClient, string folderId, string filePath)
    {
        ITemplatesClient templatesClient = new TemplatesClient(httpClient);
    
        byte[] bytes = File.ReadAllBytes(filePath);
    
        TemplateCreateVM model = new TemplateCreateVM()
        {
            Name = Path.GetFileName(filePath),
            Content = Convert.ToBase64String(bytes)
        };
    
        TemplateVM result = await templatesClient.UploadFileAsync(folderId, model);
    
        return result.Id;
    }
    

    In this example, the function retrieves a file from disk and uploads it into the folderId directory. Learn more about the parameters:

    • folderId — template directory ID.

    • model.Name — file name, so it will be displayed inside FastReports Corporate Server.

      The file name should have the extension .frx, if it is not there, then add it manually.

    • model.Content — Base64 encoded file content.

    The method returns the identifier of the uploaded template.

    Now this template can be used to prepare (create) a report and export it.

What next?