Free Support Forum - groupdocs.com

CANNOT SEE DOCUMENT FROM EXTERNAL WEBSITE groupdocs viewer 2.10.0


#1

We are using groupdocs viewer 2.10.0. I get the following message when trying to load a document from an external website Local it works fine



[ArgumentNullException: Value cannot be null. Parameter name: input] Groupdocs.Web.UI.Handlers.BaseHandler.OnException(Exception exception, HttpContext context) +643 Groupdocs.Web.UI.Handlers.ViewDocumentHandler.ProcessRequest(HttpContext context) +3457 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +341 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69

I am trying to Load it with the following script




But I always get the error

#2

Hello Divand,


We are sorry to hear that you have such issue. First of all update your Viewer with the latest version .

As for the error - it means that the document which you try to view doesn’t exists. As we can see from your code you use stream (we see it from the path ‘temp\S\XMBF3LS1X.msg’). Since that please double check that this file exists on the server where you deploy your project.

Also to be able to reproduce the issue we will need full code example that you use for the document view, please share with us full code of the web page and beck-end code of the web page where you have the Viewer. Moreover will be very useful if you will share the initialization code of the Viewer.

Thank you.

#3

this is the code for the webservice. anf then the local code. It works with the local code. I cannot Upload the whole project.


Kind regards
Divan



using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Http.Cors;
using System.Web.Services;
using Groupdocs.Web.UI;


namespace ImageViewer
{
///
/// Summary description for WebServiceProviderViewer
///
[WebService(Namespace = “http://tempuri.org/”)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class WebServiceProviderViewer : System.Web.Services.WebService
{
public WebServiceProviderViewer()
{
Viewer.SetRootStoragePath(@“c:\ViewerStorage2”);
Viewer.SetLicensePath(Server.MapPath("~/GroupDocs.Viewer.for.NET.lic"));
Viewer.EnableFileListRequestHandling(true);
}

///
/// JavaScript libraries necessary for the viewer to display.
///
/// JavaScript libraries as string.
[WebMethod]
public string GetJavaScriptLibraries()
{
return Viewer.CreateScriptLoadBlock().LoadJquery().LoadJqueryUi().UseHttpHandlers().ToString();
}

///
/// Returns JavaScript for the viewer widget
///
/// Image Number to be displayed
/// ID for the viewer container div
/// Main colour for the toolbar and thumbs button
/// JavaScript for the viewer widget as a string.
[WebMethod]
public string GetInlineDocumentScript(string imageNumber, string divID, string colour = “”)
{

List streams = new List();
bool MultipleFiles = false;
Stream ByteStream = null;
string FileName = null;
string Extension = null;
string DownloadFileName = null;

try
{
List byteStreams = JsonConvert.DeserializeObject<List>(Helpers.TapeHelper.DoRequest(“Document”, “ws_getimagepath”,
new
{
ImageNumber = imageNumber
},
Properties.Settings.Default.TapeEnvironmentCode).ToString());

streams = byteStreams.Select(path => new StreamDefinition
{
Stream = new MemoryStream(path.Stream),
FilenameExtension = path.FilenameExtension
}).ToList();

if (streams.Count() == 1)
{
ByteStream = streams.FirstOrDefault().Stream;
FileName = imageNumber;
Extension = streams.FirstOrDefault().FilenameExtension;
DownloadFileName = string.Concat(imageNumber, Extension);
}
else if (streams.Count() > 1)
{
FileName = imageNumber;

if (streams.Any(s => s.FilenameExtension == “.msg”))
{
Extension = streams.FirstOrDefault(ext => ext.FilenameExtension == “.msg”).FilenameExtension;
ByteStream = streams.FirstOrDefault(str => str.FilenameExtension == “.msg”).Stream;
DownloadFileName = string.Concat(imageNumber, Extension);
}
else
{
MultipleFiles = true;
}
}
else
{
ByteStream = new MemoryStream(File.ReadAllBytes(Properties.Settings.Default.DefaultImage));
FileName = Properties.Settings.Default.DefaultName;
Extension = Properties.Settings.Default.DefaultFormat;
DownloadFileName = string.Concat(imageNumber, Extension);
}
}
catch (Exception ex)
{
ByteStream = new MemoryStream(File.ReadAllBytes(Server.MapPath(Properties.Settings.Default.ErrorImage)));
FileName = Properties.Settings.Default.DefaultName;
Extension = Properties.Settings.Default.DefaultFormat;
DownloadFileName = Properties.Settings.Default.DefaultName;
}

string groupdocsViewerScript;

if (MultipleFiles)
{
groupdocsViewerScript = Viewer.ClientCode()
.TargetElementSelector(divID)
.Streams(streams, DownloadFileName)
.EnableRightClickMenu(true)
.ShowThumbnails(true)
.BackgroundColor(colour)
.ShowFolderBrowser(false)
.OpenThumbnails(false)
.ZoomToFitHeight()
.ToString();
}
else
{
groupdocsViewerScript = Viewer.ClientCode()
.TargetElementSelector(divID)
.Stream(ByteStream, FileName, Extension, DownloadFileName)
.EnableRightClickMenu(true)
.ShowThumbnails(true)
.BackgroundColor(colour)
.ShowFolderBrowser(false)
.OpenThumbnails(false)
.ZoomToFitHeight()
.ToString();
}

return groupdocsViewerScript;
}
}
}


/////Local Code
try
{
string imageNumber = “XM0G36X72”; ///Request.QueryString[“ImageNumber”];

List byteStreams = JsonConvert.DeserializeObject<List>(Helpers.TapeHelper.DoRequest(“Document”, “ws_getimagepath”,
new
{
ImageNumber = imageNumber
},
Properties.Settings.Default.TapeEnvironmentCode).ToString());

this.streamDefinitions = byteStreams.Select(path => new StreamDefinition
{
Stream = new MemoryStream(path.Stream),
FilenameExtension = path.FilenameExtension

}).ToArray();

if (streamDefinitions.Count() == 1)
{
this.ByteStream = streamDefinitions.FirstOrDefault().Stream;
this.FileName = imageNumber;
this.Extension = streamDefinitions.FirstOrDefault().FilenameExtension;
this.DownloadFileName = string.Concat(imageNumber, this.Extension);
}
else if (streamDefinitions.Count() > 1)
{
this.FileName = imageNumber;

if (streamDefinitions.Any(s => s.FilenameExtension == “.msg”))
{
this.Extension = streamDefinitions.FirstOrDefault(ext => ext.FilenameExtension == “.msg”).FilenameExtension;
this.ByteStream = streamDefinitions.FirstOrDefault(str => str.FilenameExtension == “.msg”).Stream;
this.DownloadFileName = string.Concat(imageNumber, this.Extension);
}
else
{
MultipleFiles = true;
}
}
else
{
this.ByteStream = new MemoryStream(File.ReadAllBytes(Properties.Settings.Default.DefaultImage));
this.FileName = Properties.Settings.Default.DefaultName;
this.Extension = Properties.Settings.Default.DefaultFormat;
this.DownloadFileName = string.Concat(imageNumber, this.Extension);
}
}
catch (Exception ex)
{
this.ByteStream = new MemoryStream(File.ReadAllBytes(Server.MapPath(Properties.Settings.Default.DefaultImage)));
this.FileName = Properties.Settings.Default.DefaultName;
this.Extension = Properties.Settings.Default.DefaultFormat;
this.DownloadFileName = string.Concat(Properties.Settings.Default.DefaultName, this.Extension);
}
finally
{
DocumentCache documentCache = new DocumentCache(Server.MapPath("~/GroupDocs.Viewer.for.NET.lic"), @“C:\ViewerStorage”);
TimeSpan timeSpan = new TimeSpan(0, 30, 0);
documentCache.RemoveOldEntries(timeSpan);
}
}


#4

Hello Divand,


Thank you for the code example. Unfortunately we can’t debug it because you use several custom classes such as “SD” and “Helpers”. Since that to be able to resolve the issue we will need entire project. You can use Google Drive or any other cloud file storage to share it with us.

If we understand you correct you use two web sites: from one you get the Viewer code and in the second you view the document. If so please investigate this documentation for how to do it in the right way.

Thank you.

#5
Good day I am using Viewer 2.12 now

Please Look at the below webservice I cannot give you the Helper code.
But all that The JsonConvert.DeserializeObject<List>(Helpers.TapeHelper.DoRequest("Document", "ws_getimagepath",
new
{
ImageNumber = imageNumber
},
Properties.Settings.Default.TapeEnvironmentCode).ToString()); return a list that does is has filename extention and bytes for each file. in the list .

public class SD
{
public string FilenameExtension { get; set; }
public byte[] Stream { get; set; }
}

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Http.Cors;
using System.Web.Services;
using Groupdocs.Web.UI;
using Groupdocs.Web.UI;


namespace ImageViewer
{
///
/// Summary description for WebServiceProviderViewer
///
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class WebServiceProviderViewer : System.Web.Services.WebService
{
public WebServiceProviderViewer()
{
Viewer.SetRootStoragePath(@"c:\ViewerStorage2");
Viewer.SetLicensePath(Server.MapPath("~/GroupDocs.Viewer.for.NET.lic"));
//Viewer.EnableFileListRequestHandling(true);
}

///
/// JavaScript libraries necessary for the viewer to display.
///
/// JavaScript libraries as string.
[WebMethod]
public string GetJavaScriptLibraries()
{
return Groupdocs.Web.UI.Viewer.CreateScriptLoadBlock().LoadJquery().LoadJqueryUi().UseHttpHandlers().ToString();
}

///
/// Returns JavaScript for the viewer widget
///
/// Image Number to be displayed
/// ID for the viewer container div
/// Main colour for the toolbar and thumbs button
/// JavaScript for the viewer widget as a string.
[WebMethod]
public string GetInlineDocumentScript(string imageNumber, string divID, string colour = "")
{
// // Fetches the file contents.
// string groupdocsViewercript;
//// String filename = @"TestDoc.docx";
// using (FileStream fileStream = JsonConvert.DeserializeObject(Helpers.TapeHelper.DoRequest("Document", "ws_getimagepath",new
// {ImageNumber = imageNumber},Properties.Settings.Default.TapeEnvironmentCode).ToString()))
// {
// groupdocsViewercript = Groupdocs.Web.UI.Viewer.ClientCode()
// .TargetElementSelector(divID)
// .Stream(fileStream, imageNumber, "docx", imageNumber)
// .EnableRightClickMenu(true)
// .ShowThumbnails(true)
// .OpenThumbnails(true)
// .ZoomToFitWidth()
// .ToString();
// }
// return groupdocsViewercript;
List streams = new List();
bool MultipleFiles = false;
Stream ByteStream = null;
string FileName = null;
string Extension = null;
string DownloadFileName = null;

try
{
List byteStreams = JsonConvert.DeserializeObject<List>(Helpers.TapeHelper.DoRequest("Document", "ws_getimagepath",
new
{
ImageNumber = imageNumber
},
Properties.Settings.Default.TapeEnvironmentCode).ToString());

streams = byteStreams.Select(path => new StreamDefinition
{
Stream = new MemoryStream(path.Stream),
FilenameExtension = path.FilenameExtension
}).ToList();

if (streams.Count() == 1)
{
ByteStream = streams.FirstOrDefault().Stream ;
FileName = imageNumber;
Extension = streams.FirstOrDefault().FilenameExtension;
DownloadFileName = string.Concat(imageNumber, Extension);
}
else if (streams.Count() > 1)
{
FileName = imageNumber;

if (streams.Any(s => s.FilenameExtension == ".msg"))
{
Extension = streams.FirstOrDefault(ext => ext.FilenameExtension == ".msg").FilenameExtension;
ByteStream = streams.FirstOrDefault(str => str.FilenameExtension == ".msg").Stream ;
DownloadFileName = string.Concat(imageNumber, Extension);
}
else
{
MultipleFiles = true;
}
}
else
{

ByteStream = new MemoryStream(File.ReadAllBytes(Properties.Settings.Default.DefaultImage));
FileName = Properties.Settings.Default.DefaultName;
Extension = Properties.Settings.Default.DefaultFormat;
DownloadFileName = string.Concat(imageNumber, Extension);
}
}
catch (Exception ex)
{
ByteStream= new MemoryStream(File.ReadAllBytes(Server.MapPath(Properties.Settings.Default.ErrorImage))) ;
FileName = Properties.Settings.Default.DefaultName;
Extension = Properties.Settings.Default.DefaultFormat;
DownloadFileName = Properties.Settings.Default.DefaultName;
}

string groupdocsViewerScript;

if (MultipleFiles)
{
groupdocsViewerScript = Viewer.ClientCode()
.TargetElementSelector(divID)
.Streams(streams, DownloadFileName)
.EnableRightClickMenu(true)
.ShowThumbnails(true)
.BackgroundColor(colour)
.ShowFolderBrowser(false)
.OpenThumbnails(false)
.ZoomToFitHeight()
.ToString();
}
else
{
groupdocsViewerScript = Viewer.ClientCode()
.TargetElementSelector(divID)
.Stream(ByteStream, FileName, Extension, DownloadFileName)
.EnableRightClickMenu(true)
.ShowThumbnails(true)
.BackgroundColor(colour)
.ShowFolderBrowser(false)
.OpenThumbnails(false)
.ZoomToFitHeight()
.ToString();
}

return groupdocsViewerScript;
}
}
}







I dont understand why its not displaying the file as the below code it does return the stream to the viewer.





<html xmlns="http://www.w3.org/1999/xhtml">
<head id="HeadControl">
<script type='text/javascript' src='http://localhost/ImageViewer/document-viewer/GetScriptHandler?name=libs/jquery-1.9.1.min.js'><script type='text/javascript' src='http://localhost/ImageViewer/document-viewer/GetScriptHandler?name=libs/jquery-ui-1.10.3.min.js'><script type='text/javascript' src='http://localhost/ImageViewer/document-viewer/GetScriptHandler?name=libs/knockout-3.2.0.js'><script type='text/javascript' src='http://localhost/ImageViewer/document-viewer/GetScriptHandler?name=libs/turn.min.js'><script type='text/javascript' src='http://localhost/ImageViewer/document-viewer/GetScriptHandler?name=libs/modernizr.2.6.2.Transform2d.min.js'><script type='text/javascript'>if (!window.Modernizr.csstransforms) $.ajax({url: 'http://localhost/ImageViewer/document-viewer/GetScriptHandler?name=libs/turn.html4.min.js', dataType: 'script', type: 'GET', async: false});<script type='text/javascript' src='http://localhost/ImageViewer/document-viewer/GetScriptHandler?name=installableViewer.min.js'><script type='text/javascript'>$.ui.groupdocsViewer.prototype.applicationPath = 'http://localhost/ImageViewer/';<script type='text/javascript'>$.ui.groupdocsViewer.prototype.useHttpHandlers = true;<script type='text/javascript' src='http://localhost/ImageViewer/document-viewer/GetScriptHandler?name=GroupdocsViewer.all.min.js'><link rel='stylesheet' type='text/css' href='http://localhost/ImageViewer/document-viewer/CSS/GetCssHandler?name=bootstrap.css' /><link rel='stylesheet' type='text/css' href='http://localhost/ImageViewer/document-viewer/CSS/GetCssHandler?name=GroupdocsViewer.all.min.css' /><link rel='stylesheet' type='text/css' href='http://localhost/ImageViewer/document-viewer/CSS/GetCssHandler?name=jquery-ui-1.10.3.dialog.min.css' />
<body id="BodyControl">
<div id="#test" style="width:600px;height:400px;position:relative">
<script type="text/javascript"> $(function () { var localizedStrings = null;var thumbsImageBase64Encoded = null;$('#test').groupdocsViewer({ localizedStrings: localizedStrings, thumbsImageBase64Encoded: thumbsImageBase64Encoded, filePath: 'temp\\S\\XMBF3LS22.msg',quality: 100,showThumbnails: true,openThumbnails: false,initialZoom: 100,zoomToFitWidth: false,onlyShrinkLargePages: false,zoomToFitHeight: true,width: 0,height: 0,backgroundColor: 'red',showFolderBrowser: false,showPrint: true,showDownload: true,showZoom: true,showPaging: true,showViewerStyleControl: true,showSearch: true,preloadPagesCount: null,preloadPagesOnBrowserSide: false,convertWordDocumentsCompletely: false,viewerStyle: 1,supportTextSelection: true,usePdfPrinting: false,toolbarButtonsBoxShadowStyle: null,toolbarButtonsBoxShadowHoverStyle: null,thumbnailsContainerBackgroundColor: null,thumbnailsContainerBorderRightColor: null,toolbarBorderBottomColor: null,toolbarInputFieldBorderColor: null,toolbarButtonBorderColor: null,toolbarButtonBorderHoverColor: null,thumbnailsContainerWidth: 0,jqueryFileDownloadCookieName: 'jqueryFileDownloadJSForGD',showDownloadErrorsInPopup: false,showImageWidth: false,showHeader: true,minimumImageWidth: 0,enableStandardErrorHandling: true,useHtmlBasedEngine: false,useHtmlThumbnails: false,useImageBasedPrinting: true,fileDisplayName: 'XMBF3LS22.msg',downloadPdfFile: false,searchForSeparateWords: false,preventTouchEventsBubbling: false,useInnerThumbnails: false,watermarkText: null,watermarkColor: null,watermarkPosition: 'Diagonal',watermarkFontSize: 0,printWithWatermark: false,supportPageReordering: false,searchHighlightColor: null,currentSearchHighlightColor: null,treatPhrasesInDoubleQuotesAsExactPhrases: false,usePngImagesForHtmlBasedEngine: false,showOnePageInRow: false,loadAllPagesOnSearch: false,useEmScaling: false,ignoreDocumentAbsence: false,supportPageRotation: false,useRtl: false,useAccentInsensitiveSearch: false,useVirtualScrolling: false,supportListOfContentControls: false,supportListOfBookmarks: false,embedImagesIntoHtmlForWordFiles: false}); });




This is the webconfig handlers


<?xml version="1.0"?>

And this is the global file


protected void Application_Start(object sender, EventArgs e) { Viewer.SetLicensePath(Server.MapPath("~/GroupDocs.Viewer.for.NET.lic")); Viewer.SetRootStoragePath(@"C:\ViewerStorage"); Viewer.EnableFileListRequestHandling(true);
}
Any help would be appreciated the viwer does not display the stream






























































#6

Hello,


Thank you for sharing this code. We have checked your web.config and found out that you use classic pipline mode and also you have missed modules section. Since that you should add such block to the system.webserver:

And such handlers for classic pipline mode:

Also we noticed that you initialized the Viewer in the Globals and then in the “WebServiceProviderViewer” - it’s wrong. You should initialize the Viewer only once (the Globals is a best place for it)

Thank you.

#7

Good day


I have added the handlers but it still no working here is a copy of the project


https://drive.google.com/file/d/0B0Zuq7qVMFRLTzhLQUVWLTVCWlk/view?usp=sharing


Kind regards
Divan

#8

Hello Divan,


Thank you for the project example. We will investigate and fix it for you. When it will be done we will notify you here.

Thank you.

#9

I appreciate all your patience with me


Kind regards
Divan

#10

Hi again,


Just to clarify few things.

In the project we can see the WebService provider which returns Viewer code on ajax (or some other) request from the another project. Also we see the default web.page with functional which made request to one more project to get the document stream and then show the document in the Viewer. Since that we need to know the logic of the project ( your use case) - does this project is used only to store the documents and return Viewer code to another project which will show the Viewer? If yes we need to know the appointment of a functional from the default.aspx.cs

Thank you.

#11

Yes the Webservice that return Viewer code to an external Page on ajax is the Part that doesnt work… We use the default Page for a local viewer and that does work.


I have attached the code I use to test it does display the viewer code but never loads the image.
https://drive.google.com/file/d/0B0Zuq7qVMFRLUHN3amxteWNOZkE/view?usp=sharing

Kind regards
Divan

#12

Is there something seriously wrong.?


#13

Hello Divend,


We have fixed your projects. Please download fixed version here . The main issue was in the hardcoded paths.

Best regards.

#14

Thank you will it work if I uncomment my code ?



#15

Hi,


Yes, it should work. But since you integrate the Viewer via calling Viewer code from another project we can assume that the code from the Page_Load method in the ImageViewer project is unnecessary.

Best regards.

#16

Thank you for all the hard work but it still doesnt work if I uncomment the code in the WebServiceProviderViewer and use that it never loads the document just displays the viewer






#17

Thank you fro all your hard work but the webservice is not working


If I use your code it displays but As soon as I use our code the image never loads


Kind regards
Divan

#18

Good day


I managed to solve the problem turns out when streaming to website with groupdocs viewer script if you use memorystream you have to set the memorystream.position = 0:

Hope you guys can use this in you knowledge base thank you for all your help much appreciated.

I have a different problem now when I try to open some files I get the following error

[ArgumentException: Illegal characters in path.]
Groupdocs.Web.UI.Handlers.BaseHandler.OnException(Exception exception, HttpContext context) +643
Groupdocs.Web.UI.Handlers.ViewDocumentHandler.ProcessRequest(HttpContext context) +3603
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +341
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Kind regards
Divan



#19

Hi,


In the commented code (code line 172) we can see that you use Filepath (screenshot). Remove this code line since you use stream.

Also we can see that you trying to get the file content - it’s a wrong way, you should simply get file stream as in such way FileStream fileStream = new FileStream(fullFilename, FileMode.Open).
And you logic should be next:
1. Get list of files from the root storage
2. Check if there is a more then 1 file
2.1 If yes - create a list of streams and use .Streams from the Viewer widget
2.2 If no - get stream of one file and use .Stream from Viewer widget
3. Generate appropriate Viewer widget code

For more info about how to work with the stream in the Viewer please check this documentation.

Thank you.

#20

Thank you I will use your advice and try to get it working


Kind regards
Divan