We're sorry GroupDocs doesn't work properply without JavaScript enabled.

Free Support Forum - groupdocs.com

How to pass filename in document viewer in .NET

We are trying to use newer groupdoc viewer in our app, however we could not find the way to pass document path to the viewer when viewer on load. It is always displaying default document from configuration.yml file.

public class ViewerController : Controller
{
        public ActionResult Index(string documentPath)
        {
            //how do I pass documentPath to the viewer.

            return this.View();
        }
}

@supahoops

There are couple of options here:

  • Default document setting
  • file query string parameter e.g. /viewer?file=sample.docx

Can you please clarify if you are running one of our demos from GitHub?

@supahoops

The second option is not working at the moment.

file query string parameter e.g. /viewer?file=sample.docx

We’re investigating this issue and update you when it will be fixed.

We have tried your second option and we are getting an error.

@supahoops

We’re looking into resolving this issue. I’m sorry for the inconvenience.

@supahoops

The issue with loading a file specified as a query string parameter has been fixed. Please clone or download MVC or WebForms Demo and try running the app. Specify the file you want to open as a query string parameter e.g. /viewer?file=sample.docx and the file should be opened as shown on the screenshot

Please let us know if it works for your use case.

Thank you for the fix, it is working.
I got another query. Do you have demo project that is build on .net core with viewer ?

@supahoops

Thank you for your feedback! Yes, for .NET Core please check GroupDocs.Viewer-for-.NET-UI repository. There couple of simple steps required to integrate Viewer in your .NET Core web application.

  1. Install packages
dotnet add package GroupDocs.Viewer.UI
dotnet add package GroupDocs.Viewer.UI.SelfHost.Api
dotnet add package GroupDocs.Viewer.UI.Api.Local.Storage
dotnet add package GroupDocs.Viewer.UI.Api.Local.Cache
  1. Configure middlewares
public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services
            .AddGroupDocsViewerUI();

        services
            .AddControllers()
            .AddGroupDocsViewerSelfHostApi(config =>
            {
                //Trial limitations https://docs.groupdocs.com/viewer/net/evaluation-limitations-and-licensing-of-groupdocs-viewer/
                //Temporary license can be requested at https://purchase.groupdocs.com/temporary-license
                //config.SetLicensePath("c:\\licenses\\GroupDocs.Viewer.lic"); // or set environment variable 'GROUPDOCS_LIC_PATH'
            })
            .AddLocalStorage("./Files")
            .AddLocalCache("./Cache");
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        app
            .UseRouting()
            .UseEndpoints(endpoints =>
            {
                endpoints.MapGroupDocsViewerUI(options =>
                {
                    options.UIPath = "/viewer";
                    options.APIEndpoint = "/viewer-api";
                });

                endpoints.MapGroupDocsViewerApi(options =>
                {
                    options.ApiPath = "/viewer-api";
                });
            });
    }
}
  1. Create folder Files in the root directory and add some files
  2. Run the app and navigate to /viewer

You can also download sample-viewer-app.zip (88.0 KB) that is ready to run.

Please let us know if you have any issues with using Viewer in .NET Core apps.