Upload a new template
One of the main features of FastReport Corporate Server is storing templates, reports and other data in the cloud. This article will describe a way to upload your ready template to FastReport.Cloud templates storage.
Getting started
You will need the following tools and features:
Knowledge on how to use API key in FastReport Corporate Server.
This article does not include the information about authentication and authorization.
A C# code editor or a text editor like Visual Studio Code.
A report template.
It can be prepared using free software FastReport Community Designer.
Active subscription for FastReport Corporate Server.
Internet access.
Please, note: This tutorial assumes that you already know how to develop your application with the C# programming language.
Please, note: The descriptions above are provided for the recommended tools.
Instructions
You need to get the subscription root directory identifier. This identifier will never change, so you can save it and not make a request every time before loading a new template.
To request the root directory, use the <xref:FastReport.Cloud.ITemplateFoldersClient.GetRootFolderAsync(System.String)> method.
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 subscription identifier; if it is not specified (null), the user's first subscription will be returned.To upload the required template, use the <xref:FastReport.Cloud.ITemplatesClient.UploadFileAsync(System.String,FastReport.Cloud.TemplateCreateVM)> method.
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 gets a file from the disk and loads it into the
folderId
directory. More details on the parameters:folderId
— identifier of the template directory.model.Name
— file name as it will be displayed inside FastReport Corporate Server.The file name must contain the extension
.frx.
If it does not, add the extension manually.model.Content
— file content encoded in base64.
The method returns the identifier of the uploaded template.
Now this template can be used to prepare (build) a report and export.