[]
The steps below describe how to create a simple ASP.NET Core web application that uses GcDataViewer to view data files.
Open Microsoft Visual Studio and select Create a new project | ASP.NET Core Web App and name it. In this example, we have named it as “GcDataViewerApp”.
Open the project in File Explorer and locate the wwwroot > lib directory.
Right-click on lib folder and select Open in Terminal. Run the following command to install GcDataViewer.
npm install @grapecity/gcdataviewer
Observe that GcDataViewer gets installed at following location:
GcDataViewerApp\wwwroot\lib\node_modules\@grapecity\gcdataviewer
In Solution Explorer, right click wwwroot folder of the project and select Add > New Item to add a new HTML file named 'index.html'.
To initialize GcDataViewer, add the following code to index.html.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="description" content="Grapecity Data Viewer">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, user-scalable=yes" />
<script type="text/javascript" src="lib/node_modules/@grapecity/gcdataviewer/gcdataviewer.js"></script>
<title>Grapecity Data Viewer Sample</title>
<script>
function loadDataViewer(selector) {
//GcDataViewer.LicenseKey = 'your_license_key';
var viewer = new GcDataViewer(selector, {});
}</script>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body onload="loadDataViewer('#root')">
<div id="root" class="gcdataviewer"></div>
</body>
</html>
In Visual Studio, add a new stylesheet 'style.css' in wwwroot/css folder of the project and add following code.
.gcdataviewer {
height: 100%;
}
To start the application with index.html by default, in Program.cs file, replace the default methods with following code.
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
}
app.UseHttpsRedirection();
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapRazorPages();
app.Run();
Build and run the application. A page displaying GcDataViewer opens in your default browser.
User can use Open document button() on the top-left of the GcDataViewer control to open a file.
For more information, see Load a File.