Click or drag to resize

PdfLiteStorageProvider Class

Defines the contract that RAD PDF implements to manage storage for Lite Document instances.
Gets or sets an object that specifies the storage provider used for Lite Documents with RAD PDF applications using this integration provider.
Inheritance Hierarchy

Namespace:  RadPdf.Lite
Assembly:  RadPdfStandard (in RadPdfStandard.dll) Version: 4.1.0.0 (4.1.0.0)
Syntax
public abstract class PdfLiteStorageProvider

The PdfLiteStorageProvider type exposes the following members.

Constructors
  NameDescription
Public methodPdfLiteStorageProvider
Creates a new instance of the PdfLiteStorageProvider class.
Top
Methods
  NameDescription
Public methodDeleteData
Deletes all data from the PdfLiteStorageProvider for the given session.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetData
Gets data from the PdfLiteStorageProvider for the given session and subtype.
Public methodGetDataStream
Gets data, as a Stream from the PdfLiteStorageProvider for the given session.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodSetData
Sets data from the PdfLiteStorageProvider for the given session.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Remarks

The PdfLiteStorageProvider is responsible for storing information associated with a given Lite Document session.

By default, RAD PDF uses the DefaultPdfLiteStorageProvider which uses the RAD PDF System Service and its storage.

Examples
The following example overrides the default PdfIntegrationProvider to create a custom Integration Provider for the web application. This custom provider stores data simply using the file system.
C#
using System;
using System.IO;
using System.Web;

using RadPdf.Integration;

public class CustomPdfIntegrationProvider : PdfIntegrationProvider
{
    public CustomPdfIntegrationProvider() : base()
    {
        this.LiteStorageProvider = new CustomPdfLiteStorageProvider(@"C:\RadPdfStorage\");
    }
}
C#
using System;
using System.IO;
using System.Web;

using RadPdf.Lite;

public class CustomPdfLiteStorageProvider : PdfLiteStorageProvider
{
    private readonly DirectoryInfo _dir;

    public CustomPdfLiteStorageProvider(string path) : base()
    {
        _dir = new DirectoryInfo(path);

        if (!_dir.Exists)
        {
            _dir.Create();
        }
    }

    private string GetPath(PdfLiteSession session, int subtype)
    {
        return Path.Combine(_dir.FullName, session.ID.ToString("N") + "-" + subtype.ToString() + ".dat");
    }

    public override void DeleteData(PdfLiteSession session)
    {
        FileInfo[] files = _dir.GetFiles(session.ID.ToString("N") + "*");

        foreach (FileInfo file in files)
        {
            lock (string.Intern(file.FullName))
            {
                file.Delete();
            }
        }
    }

    public override byte[] GetData(PdfLiteSession session, int subtype)
    {
        string path = GetPath(session, subtype);

        lock (string.Intern(path))
        {
            if (!File.Exists(path))
            {
                return null;
            }

            return File.ReadAllBytes(path);
        }
    }

    public override void SetData(PdfLiteSession session, int subtype, byte[] value)
    {
        string path = GetPath(session, subtype);

        lock (string.Intern(path))
        {
            File.WriteAllBytes(path, value);
        }
    }
}
The following Program.cs file registers the above custom Integration Provider. This example assumes that CustomPdfIntegrationProvider is in namespace referenced by your ASP.NET web application.
C#
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

using RadPdf;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddSession();

// Setup WebApplication
var app = builder.Build();
app.UseStaticFiles();
app.UseRouting();
app.UseSession();
app.UseAuthorization();

// Or however you normally process page requests
app.MapRazorPages();

// Create middleware settings
RadPdfCoreMiddlewareSettings settings = new RadPdfCoreMiddlewareSettings()
{
    // Add SQL Server Connection String, if not using Lite Documents
    // Sample connection string below connects to a SQL Server Express instance on localhost
    // TrustServerCertificate=True is set to avoid a trust exception (e.g. "The certificate chain was issued by an authority that is not trusted.")
    // ConnectionString = @"Server=.\SQLExpress;Database=RadPdf;Trusted_Connection=Yes;TrustServerCertificate=True;",

    // Add License Key
    LicenseKey = "DEMO",

    // Attach the Integration Provider
    IntegrationProvider = new CustomPdfIntegrationProvider()

    // To run RAD PDF without the System Service, add UseService = false
    // If using Lite Documents without the System Service, a LiteStorageProvider must also be implemented
    //UseService = false
};

// Add RAD PDF's middleware to app
app.UseRadPdf(settings);

app.Run();
See Also