Giter Site home page Giter Site logo

kore75 / spwordreport Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 1.77 MB

SPWebpart for creating Pdf Report through a .NET WebAPI

JavaScript 23.98% TypeScript 33.95% SCSS 0.85% HTML 15.47% C# 18.49% CSS 7.26%
azure net-core rest-api sharepoint-online spfx-webpart synchfusion pdf-report pdf word sharepoint

spwordreport's Introduction

SP React Webparts with .NET WebAPI To Create Pdf Reports

Azure Active Directory enables connectivity to various APIs. The SharePoint Online web part utilizes Azure AD for authentication.

MSAL within React can be employed to generate JSON Web Tokens, which are authenticated by the web API and utilized for an On-Behalf-Of (OBO) flow to request additional access tokens for SharePoint.

The report template is a Word document with mail merge fields.

The Syncfusion library offers advanced mail merge capabilities, which can populate these fields. Although this Word feature is typically utilized for serial letters, it proves quite useful in this specific scenario.

Word Template

The web part can be configured to utilize a designated template and display a list of items for which entries can be created.

Properties

SpFx WebPart Used for List

Properties

The end result is an pdf File stored as attachment of then sp liste item entry.

Source

Properties

flowchart LR
    A[SP React WebPart] -->|Get Token | B(.NET Core WebAPI)
    B --> |1 Read Template | C[SP Online]
    B --> |2 Read Item List Data| D[SP Online]
    B --> |3 Store Report File as Attachment| E[SP Online]    
Loading

Used Components

  • Spfx React Webpart
  • Pnp Sdk fore Reading Data from SP
  • .NET Core WebAPI
  • Blazor WASM App for Testing Purposes
  • Syncfusion Library for creating serial word documents and PDF Reports This requires additional licencing depending on our scenario

Visual Studio Template

The template used is a hosted Blazor WebAssembly (WASM) application with Windows Integrated authentication using MSAL.

The boilerplate code will establish two web app registrations in Azure and offer most of the configuration settings out of the box.

The .NET WebAPI Modifications

The authentication for On-Behalf-Of (OBO) is configured by utilizing the EnableTokenAcquisitionToCallDownstreamApi method.

// Add services to the container.
            builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
                .AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("AzureAd"))
                .EnableTokenAcquisitionToCallDownstreamApi()
                  .AddInMemoryTokenCaches();

Using PNP Sdk is quite easy. Just add

private async Task<PnPContext> createSiteContextForUser()
{
    var siteUrl = new Uri(_pnpCoreOptions.Sites["ReportSite"].SiteUrl);

    return await _pnpContextFactory.CreateAsync(siteUrl,
                    new ExternalAuthenticationProvider((resourceUri, scopes) =>
                    {
                        return _tokenAcquisition.GetAccessTokenForUserAsync(scopes,user:this.User);
                    }
                    ));
}

spwordreport's People

Contributors

kore75 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.