News combit Dev Blog

How to Automatically Export Reports to Cloud Storage Services

Posted: Thursday, April 18, 2019 | 0 comment(s)
 
With List & Label you can export reports in different formats like PDF, Word, Excel and many more. The resulting reports can either be stored directly in the file system or - in .NET - in a stream, in order to transfer them manually into a database, a document management system or similar. Reports can also be automatically stored directly in so-called cloud storage services. The cloud storage providers for GoogleDrive, Microsoft OneDrive or Dropbox are available in List & Label for .NET for this purpose.

In order for the List & Label .NET component to transfer the exported reports directly and automatically to one of the supported cloud storage services, at least one additional assembly reference is required, depending on the target system. The source code for the required assemblies is available on GitHub and can be adapted or extended at will. You can also use the cloud storage providers for scheduled reports in the combit Report Server. Below you will find some examples showing how the providers can be used in your own code.

First, a simple file-based PDF export with List & Label is shown. The report is then uploaded to GoogleDrive as a stream, including the login data, so that no separate authentication by the user is required. For this purpose, a special RefreshToken is required:


...
using (ListLabel LL = new ListLabel())
{
    // D:  Datenquelle und Optionen für List & Label definieren
    // US: Define data source and options for List & Label
    // ...
 
    // D:  Bericht mit List & Label als PDF nach _filePath exportieren
    // US: Export report with List & Label as PDF document into _filePath
    ExportConfiguration exportConfiguration = new ExportConfiguration(LlExportTarget.Pdf, _filePath, "simple.lst")
    {
        ShowResult = false
    };
     
    LL.Export(exportConfiguration);
     
    // D:  Bericht nach GoogleDrive hochladen
    // US: Upload report into GoogleDrive
    var stream = new FileStream(_filePath, FileMode.Open, FileAccess.Read);
    GoogleDriveUploadParameter googleDriveUploadParameter = new GoogleDriveUploadParameter()
    {
        MimeType = GetMimeType(_filePathh),
        UploadStream = stream,
        CloudFileName = Path.GetFileName(_filePath),
        CloudPath = "" // empty string means root folder
    };
     
    GoogleDriveCredentials googleDriveUploadCredentials = new GoogleDriveCredentials()
    {
        ApplicationName = "<Application name of your Google App>",
        ClientId = "<Client Id of your Google App>",
        ClientSecret = "client_secret.json",
        RefreshToken = "<Refresh token of your Google App>"
    };
    LL.UploadSilently(googleDriveUploadParameter, googleDriveUploadCredentials);
 
    stream.Close();
}
...


The following code shows how to upload a stream-based report to Microsoft OneDrive that has been generated manually before. However, this will force the user to enter the logon credentials to Microsoft OneDrive:

...
using (ListLabel LL = new ListLabel())
{
    // D:  Datenquelle und Optionen für List & Label definieren
    // US: Define data source and options for List & Label
    // ...
     
    // D:  Bericht mit List & Label als PDF direkt in einen Stream exportieren
    // US: Export report with List & Label as PDF document into stream
    var stream = new FileStream(_filePath, FileMode.CreateNew);
    ExportConfiguration exportConfiguration = new ExportConfiguration(LlExportTarget.Pdf, stream, "simple.lst")
    {
        ShowResult = false
    };
    LL.Export(exportConfiguration);
     
    // D:  Bericht nach Microsoft OneDrive hochladen
    // US: Upload report into Microsoft OneDrive
    MicrosoftOneDriveUploadParameter microsoftOneDriveUploadParameter = new MicrosoftOneDriveUploadParameter()
    {
        ApplicationId = "<Application Id of your Microsoft App>",
        UploadStream = stream,
        CloudFileName = Path.GetFileName(_filePath),
        CloudPath = "Documents"
    };
    LL.Upload(microsoftOneDriveUploadParameter);
}
...


The GoogleDrive and Microsoft OneDrive examples above all show a separate upload of the previously exported report using the upload feature of the respective cloud storage provider. Of course, any files can be uploaded at any time, completely independent of List & Label. With the help of an extension method for the Export function, which each Cloud Storage Provider contains, the export of the report including the upload can be carried out completely in one go. Which Cloud Storage Provider is used depends on the specific parameter. This would look like a direct file-based export including upload to Dropbox:

...
using (ListLabel LL = new ListLabel())
{
    // D:  Datenquelle und Optionen für List & Label definieren
    // US: Define data source and options for List & Label
    // ...
     
    // D:  Optionen für den Export des Berichts definieren
    // US: Define export options for the report
    ExportConfiguration exportConfiguration = new ExportConfiguration(LlExportTarget.Pdf, _filePath, "simple.lst")
    {
        ShowResult = false
    };
     
    // D:  Bericht direkt nach dem Exportieren nach Dropbox hochladen
    // US: Upload the exported report into Dropbox
    DropboxExportParameter dropBoxExportParameter = new DropboxExportParameter()
    {
        CloudFileName = Path.GetFileNameWithoutExtension(_filePath),
        CloudPath = "Documents"
    };
    LL.Export(exportConfiguration, dropBoxExportParameter, "<Your DropBox App Key>");
}
...

In the individual implementations of the Cloud Storage Providers you will find further helpful functions and detailed code documentation. Browse around a bit or even implement new features specifically for your needs. Of course, we are also happy to receive pull requests on GitHub to make updates available to the entire List & Label community.




Author: Daniel Stein
Consultant, Development & Cooperations

Daniel trained with combit as a programmer specialized in software development. He is now engaged in software development and fosters business cooperations. He conducts software trainings and supports the sales team as technical advisor. In his spare time he enjoys mountainbiking around Lake Constance and in the Swiss Alps closeby.


 

RSS
combit Development BlogRSS
What’s this blog for?
A place to share updates about the ongoing development of our products. General musings on the software industry included.
Archive
January 2021 (1)
December 2020 (2)
November 2020 (1)
October 2020 (2)
September 2020 (1)
August 2020 (2)
July 2020 (1)
June 2020 (1)
May 2020 (2)
April 2020 (2)
March 2020 (2)
February 2020 (1)
January 2020 (1)
December 2019 (1)
November 2019 (2)
October 2019 (2)
September 2019 (2)
August 2019 (2)
July 2019 (2)
June 2019 (2)
May 2019 (1)
April 2019 (0)
April 2019 (1)
March 2019 (1)
February 2019 (1)
January 2019 (1)
December 2018 (1)
November 2018 (2)
October 2018 (4)
September 2018 (4)
August 2018 (2)
July 2018 (2)
June 2018 (2)
May 2018 (1)
April 2018 (1)
March 2018 (1)
February 2018 (2)
January 2018 (1)
December 2017 (1)
November 2017 (2)
October 2017 (3)
September 2017 (3)
August 2017 (2)
July 2017 (2)
June 2017 (1)
May 2017 (2)
April 2017 (1)
March 2017 (1)
February 2017 (1)
January 2017 (2)
December 2016 (1)
November 2016 (1)
October 2016 (4)
September 2016 (5)
August 2016 (2)
July 2016 (2)
June 2016 (3)
May 2016 (2)
April 2016 (3)
March 2016 (3)
February 2016 (1)
January 2016 (2)
December 2015 (2)
November 2015 (1)
October 2015 (4)
September 2015 (5)
August 2015 (2)
July 2015 (2)
June 2015 (2)
May 2015 (1)
April 2015 (2)
March 2015 (1)
February 2015 (1)
January 2015 (1)
December 2014 (2)
November 2014 (1)
October 2014 (1)
September 2014 (2)
August 2014 (1)
July 2014 (2)
June 2014 (1)
May 2014 (2)
April 2014 (1)
March 2014 (2)
+1 800 256 3608 (toll-free North America only)