Different name for GroupDocs temp folder

Hello Dhivya,


Sorry for the delay and thank you for the description. In such case the only way that you can achieve your goal is to use stream in the Viewer.

For example you can try to use such logic:
1. In the Globals use such initialization code:
Viewer.SetRootStoragePath(Server.MapPath("~/App_Data"), Server.MapPath("~/App_Data/Cache"));
2. In the controller of the web page with Viewer (for example lets say it will be Index action):
public ActionResult Index()
{
const string testFilesDir = “~/testfiles/”;
string[] filePaths ={
@Server.MapPath(testFilesDir + “candy.pdf”),
};

StreamDefinition [] streamDefinitions = filePaths.Select(path => new StreamDefinition
{
Stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read),
FilenameExtension = Path.GetExtension(path)
}).ToArray();
return View(streamDefinitions);
}
3. In the view file:
@model StreamDefinition[]
@{
StreamDefinition[] streamDefinitions = Model;
}

@(Html.ViewerClientCode()
.TargetElementSelector("#test2")
.Streams(Model, “candy_timesheet”)
.OpenThumbnails()
.ZoomToFitWidth()
.BackgroundColor("#777")
.Locale(“es-ES”)
.ShowHeader(false)
.UseHtmlBasedEngine(false)
.UseInnerThumbnails()
)
@{
foreach (StreamDefinition streamDefinition in streamDefinitions)
{
streamDefinition.Stream.Dispose();
}
}

Please note that const string testFilesDir should be the path that you will use currently.
With such logic your App_Data folder will not contain any files that you view only the cache.

Also please find attached example code source.

Best regards.

Hi,


We have thousands of documents and we open the preview and loads it only when the user clicks on the link after doing some other operations in jquery. So we right now have the below code to initialise the viewer. How do I return the StreamDefinition from my controller to my jquery in ajax call?

$(tabName).groupdocsViewer({
filePath: data.fileName,
docViewerId: ‘doc_viewer’ + tabName,
PreloadPagesCount: 1,
localizedStrings: localizedStrings, thumbsImageBase64Encoded: thumbsImageBase64Encoded,
quality: 100, showThumbnails: true, openThumbnails: false, initialZoom: 100,
zoomToFitWidth: true, onlyShrinkLargePages: false, zoomToFitHeight: false, width: 0, height: 0, backgroundColor: null,
showFolderBrowser: false, showPrint: true, showDownload: true, showZoom: true, showPaging: true, showViewerStyleControl: true,
showSearch: true, 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: true,
useHtmlThumbnails: false, useImageBasedPrinting: true, fileDisplayName: docDesc + ‘.’ + docExtn, 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
});

Thanks,
Dhivya

This is my angularjs call and I am not able to receive the streamdefinition here.



$http({
method: “POST”,
url: myaction,
data: docPath,
}).success(function (data, status, headers, config) {
}
Please let me know what should be my responseType to get StreamDefinition as return value.

Thanks,
Dhivya

Hello Dhivya,


Thank you for the question. In such case you need to update your code with such one:

1. In the view change your ajax call in such way:


2. In the controller (I don’t know how your action called since that lets say it’s name is Ajax()):
public ActionResult Ajax()
{
String filename = “candy.pdf”;
//You can obtain a stream as you want and from wherever you want. Here we get stream from file
String path = Server.MapPath("~/testfiles/"+ filename);
System.IO.Stream ByteStream = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read);
string groupdocsViewerScript = Groupdocs.Web.UI.Viewer.ClientCode()
.TargetElementSelector("#test")
.Stream(ByteStream, filename, “pdf”)
.Height(900)
.ToString();

return Content(groupdocsViewerScript, “text/plain”);
}

That’s all.

In few words you just need to follow this logic:
1. From the view you made ajax call to some action with file name in the data.
2. In the action you get file name, then you get it’s stream
3. In same action you will generate Viewer code with this stream (please update options here as you need)
4. Return generated Viewer code as a string
5. In the success function of the ajax call add HTML content to the page. Here you just need to note that in such case you need two DIVs for the Viewer. First with id=“container” in the example will be used as main div in which you will append Viewer div and it’s JavaScript generated in the controller.

Best regards.

Hi,

I have couple of questions.

1. Does the viewer really needs to copy the file in the form of stream for generating the preview? Isn't the path alone enough? Some of the files are very large and takes forever to get the filestream.


Thanks,
Dhivya

Hi Dhivya,


Thank you for these questions.

1. In your use case using of stream is an only way to achieve your goal - to store cache in one place inside the application.
2. Full code of the widget will be:
string groupdocsViewerScript = Groupdocs.Web.UI.Viewer.ClientCode()
.TargetElementSelector("#test")
.Stream(ByteStream, filename, “pdf”)
.PreloadPagesCount(1)
.Quality(100)
.ShowThumbnails(true)
.OpenThumbnails(false)
.Zoom(100)
.ZoomToFitWidth(true)
.Width(0)
.ShowFolderBrowser(false)
.SupportTextSelection(true)
.UsePdfPrinting(false)
.ShowDownloadErrorsInPopup(false)
.ShowImageWidth(false)
.EnableStandardErrorHandling(true)
.UseHtmlBasedEngine(true)
.DownloadPdfFileIfPossible(false)
.SearchForSeparateWords(false)
.ShowHeader(true)
.Height(0)
.ToString();

All other options that you have is set to default values - since that you not need to set them here. Also if you will need to change some other option value you will find all options as shown on the screenshot

Best regards.

Hi again,


To clear the cache folder you should use such code:
DocumentCache documentCache = new DocumentCache(Server.MapPath("~/GroupDocs.Viewer.for.NET.lic"), Server.MapPath("~/App_Data"));
TimeSpan timeSpan = new TimeSpan(0, 30, 0);
documentCache.RemoveOldEntries(timeSpan);

It will delete all files which older then 30 minutes.

Thank you

Hi,


Thanks for the solution it worked.

Regarding the first answer, are you saying there will be a performance hit if we use stream instead of the other way?

Thanks,
Dhivya

Hi,


If you will use stream you will not get performance issues - all will work with same performance as in a common way. You must use stream only because the temp files will be stored in one place in such case.

Thank you.

Perfect!! Thanks a lot. Everything is working now as required.


Thanks,
Dhivya

Hi


Glad to hear that.

Best regards.

Hi,


I have this new issue when I try to view an excel sheet with quotes as the Sheet name. The error is coming as Uncaught SyntaxError: Unexpected string. Tried attaching the excel but the forum is not allowing me to attach the excel files. The sheet name is test !""£$

Please help.

Thanks,
Dhivya

Hi,


The issue reason is that that such symbols are restricted by the web server. Please avoid using such symbols for the folder or file names

Best regards.

Hi,


The issue is its not the file or folder name but its the excel’s one of the worksheet name. We do have some documents where the sheet name needs to have “”. Can this be handled?

Thanks,
Dhivya

Hi,


Sorry but this issue is a common web issue which doesn’t related with our Viewer.
Please rename such sheet names.

Best regards.