We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

PreviewHandler

Hallo,

can I somehow register (or so) a previewhandler for another filetype than pics? Lets say doc (via docio) or pdf.

1 Reply

AB Ashokkumar Balasubramanian Syncfusion Team June 13, 2017 11:53 AM UTC

Hi Carsten, 
 
We have analyzed your requirement (Preview the word document). We can achieve your requirement by using RTE component. Initially, in “BeforeOpen” event of FileExplorer, pass the document path to the AJAX handling “Importing” method that is available in the controller part. Then the “Importing” method process the word document and return the document content to the AJAX success method, then we should pass the returned content to the “setHtml” method of RTE component. Please refer the below code block. 
 
[SCRIPT]  
  
function OnBeforeOpen(args) { 
            if (args.itemType == "File" && (/\.(docx)$/i).test(this._selectedFile)) { 
                var file = args.model.selectedFolder + args.model.selectedItems[0]; 
                $.ajax({ 
                    url: '@Url.Action("Importing", "FileExplorer")', 
                    type: "POST", 
                    dataType: "json", 
                    data: { FilePath: file }, 
                    success: function (data) { 
                        var rte = $("#rteSample").ejRTE("instance"); 
                        rte.setHtml(data); 
                        var dialogObj = $("#dialogAPI").ejDialog("instance"); 
                        dialogObj.option("title", args.model.selectedItems[0]); 
                        dialogObj.open(); 
                    } 
                }); 
 
            } 
        } 
[Controller]  
  
public object Importing(string FilePath) 
        { 
            string HtmlString = string.Empty; 
            string path = System.Web.HttpContext.Current.Server.MapPath(FilePath); 
 
            //var path = FilePath; 
 
            if (path != null) 
            { 
                using (var mStream = new MemoryStream()) 
                { 
                    new WordDocument(path).Save(mStream, FormatType.Html); 
                    mStream.Position = 0; 
                    HtmlString = new StreamReader(mStream).ReadToEnd(); 
                }; 
 
                HtmlString = ExtractBodyContent(HtmlString); 
 
                foreach (var item in DecodeKeys()) 
                { 
                    HtmlString = HtmlString.Replace(item.Key, item.Value); 
                } 
            } 
            else HttpContext.Response.Write("Select any file to upload."); 
            return Json(HtmlString); 
        } 
For your convenience, we have prepared simple sample, it can be downloaded in below location.  
  
  
To know more details about this requirement, please refer the below forum. 
  
 
Please let us know, if you have any other concerns.  
  
Regards,  
Ashokkumar B.  


Loader.
Live Chat Icon For mobile
Up arrow icon