GroupDocs.Viewer issue with ASP.NET MVC

I’m trying to get the most basic implementation of GroupDocs.Viewer to work in ASP.NE MVC following the steps at http://groupdocs.com/docs/display/viewernet/How+to+use+GroupDocs.Viewer+for+.NET+in+an+ASP.NET+MVC+Project with little success.
global.asax.cs looks like:

Viewer.InitRoutes();
Viewer.SetLicensePath(Server.MapPath(@“~/GroupDocs.Viewer.for.NET.lic”));
View looks like:

@using Groupdocs.Web.UI
@{
Layout = null;
}

OfflineViewer
body {
margin: 0;
padding: 0;
}

body div {
width: 100%;
height: 100%;
}

@Html.CreateViewerScriptLoadBlock()
@(Html.ViewerClientCode()
.TargetElementSelector(“#OfflineViewer”)
.FilePath(string.Format(@“C:\WebFiles{0}”, ViewData[“FileName”]))
.ZoomToFitWidth())

The HTML that is generated contains:
All http://localhost:12345/document-viewer/... requests come back with a 404 and the page doesn’t render a thing.

Hello,


We are sorry to hear that you have such issue. In your Global.asax.cs file you have missed these two code lines after Viewer.InitRoutes():

Viewer.SetRootStoragePath(Server.MapPath("~/testfiles/"));
Viewer.EnableFileListRequestHandling(true);

Please note: “testfiles” - is a sample folder name, you should replace it with your folder name which you will use as a root storage for the files which you will view.

Also you should remove string.Format(@“C:\WebFiles{0}”, from the .FilePath parameter of the widget and leave there only file name.

I solved the issue by moving those 2 lines at the top of the Application_Start() (before any other routing).
At this point the viewer shows up, and I am rendering a jpg, but the jpg does not show up. If I print or save, it prints and saves correctly. I can see all http requests made by the browser and there is a http://localhost:12345/document-viewer/GetDocumentPageImage?path=24219408891.jpg... that returns the image, but it doesn’t get displayed.
The helper call I use is:
@(Html.ViewerClientCode()
.TargetElementSelector("#OfflineViewer")
.ShowFolderBrowser(false)
.ShowSearch(false)
.ShowThumbnails(false)
.SupportListOfContentControls(false)
.SupportPageReordering(false)
.SupportPageRotation(false)
.SupportTextSelection(false)
.UsePdfPrinting(true)
.UseHtmlBasedEngine(false, true, false, true)
.FilePath(string.Format(@"{0}.jpg", ViewData[“boxFileId”]))
.ZoomToFitWidth())
Any suggestions?

Another thing, before I turned off the thumbnails, it was showing the thumbnail, but never the actual image, even if I clicked on it.

Hello,


Could you please share with us your controller file and the image file which you try to view that we can try to reproduce the issue.

Also please make sure that you Application_Start() looks like on the screenshot .

I added the line Viewer.EnableFileListRequestHandling(true); to global.asax. The controller action method is only setting the ViewData[“boxFileId”] with an ID it receives and calls View(), only 2 lines. The image is http://1drv.ms/18fRzIO, but all my other images behave the same.

And the same thing happens for Excel files, those say “loading your content” and never load, but if I download or print all works fine. Same outcome in both Chrome and IE.


This is a proof of concept that your sales folks are aware of, I could really use some help here.

Hello,


From your last message that you have added only EnableFileListRequestHandling to the global we can assume that you missed Viewer.SetRootStoragePath(); which should be added to the globals and should set root storage folder. Since you didn’t set root storage path the viewer can’t find file which you try to view.
My Application_Start below:

protected void Application_Start()
{
Viewer.InitRoutes();
Viewer.SetLicensePath(Server.MapPath(@"~/GroupDocs.Viewer.for.NET.lic"));
Viewer.SetRootStoragePath(Path.GetTempPath());
Viewer.EnableFileListRequestHandling(true);

WebApiConfig.Register(GlobalConfiguration.Configuration);
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);

var webformVE = ViewEngines.Engines.OfType().FirstOrDefault();
ViewEngines.Engines.Remove(webformVE);

try
{
SAMLConfiguration.Load();
}
catch (Exception ex)
{
string s = ex.Message;
}

Database.SetInitializer(null);
}

I am setting root storage to the temp folder which makes sense for the application, the files are there, GroupDocs.Viewer control show up, download works, print works, /document-viewer/ViewDocument comes back successful and returns number of pages and all the information, then /document-viewer/GetDocumentPageImage (for both Excel pages) come back fine and the result show the pages from my Excel document, but the control keeps telling me that it is rendering. There are no JS errors in the console. Basedon this, it doesn't look like it's not finding my files (JPG or Excel).

My view is as simple as it can get. I mean if you have a simple sample for MVC (aside for the one from the site that doesn't compile), I would appreciate if you could share it with me, I am trying to do the simplest thing possible, just render some simple documents.

For completion, my view is this:

@using Groupdocs.Web.UI

@{
Layout = null;
}


OfflineViewer
body {
margin: 0;
padding: 0;
}

body div {
width: 100%;
height: 100%;
}
@Html.CreateViewerScriptLoadBlock()

@(Html.ViewerClientCode()
.TargetElementSelector("#OfflineViewer")
.ShowFolderBrowser(false)
.ShowSearch(false)
.ShowThumbnails(false)
.SupportListOfContentControls(false)
.SupportPageReordering(false)
.SupportPageRotation(false)
.SupportTextSelection(false)
.UsePdfPrinting(true)
.UseHtmlBasedEngine(false, true, false, true)
.FilePath(ViewData["fileName"].ToString())
.ZoomToFitWidth())

Even if I go to bare bones like below, I can see the thumbnails for the images or Excel file but not the content. What is the minimal code I need to use to actually get GroupDocs.Viewer to render?


@using Groupdocs.Web.UI

@{
Layout = null;
}


OfflineViewer
body {
margin: 0;
padding: 0;
}

body div {
width: 100%;
height: 100%;
}
@Html.CreateViewerScriptLoadBlock()

@(Html.ViewerClientCode()
.TargetElementSelector("#OfflineViewer")
.FilePath(ViewData[“fileName”].ToString()))

Hello,


Please download example project here . You can try to view your images in this example, put your images to the “testfiles” folder and update file name to view here: .FilePath(“candy.pdf”)

Thank you, that worked and my code worked the moment I switched to .UseHtmlBasedEngine(). If I change to .UseHtmlBasedEngine(false), it stops working - that’s OK for now but I know my client will be asking for non-HTML rendering for PPTX files - any suggestions how to fix that?


Also, are there any ways to check if a file format can be rendered or not via an API call or just refer to the documentation?

Thank you!

Hello,


We glad to hear that it works now. You can check if the file format can be rendered with such method: public int GetPageCount(string documentPath)
if this method returns number of pages - document can be rendered. So simply need to check if the number of pages returned or not in the controller and if check is successful continue with Viewer loading, if not show error message.

Please share with us (if possible) your documents that you try to view that we can reproduce the issue with rendering.

Thank you.