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
close icon

Open file

Hi,
In FileExplorer, how can I open documents in shared folder “//Server/SharedFolder” with computer software (exp: open xlsx file format with MS Excel) without downloaded it.

Regards,
Anis



13 Replies

AB Ashokkumar Balasubramanian Syncfusion Team May 4, 2017 01:12 PM UTC

Hi Anis, 
 
We have analyzed your requirement (“How can I open documents in shared folder “//Server/SharedFolder” with computer software”). You can achieve your requirement by “beforeOpen” event of FileExplorer component. In “beforeOpen” event of FileExplorer, you should pass the FilePath to the AJAX handling method ( Openingfile ). In Openingfile method, we have handled the File Opening operation based on corresponding Computer software. Please refer the below code block.  
 
[Script] 
 
function OnbeforeOpen(args) { 
        if (args.itemType == "File") { 
            args.cancel = true; 
            var filename = args.model.selectedFolder + args.model.selectedItems[0]; 
            $.ajax({ 
                url: '@Url.Action("Openingfile", "FileExplorer")', 
                type: "POST", 
                dataType: "json", 
                data: { filename: filename }, 
                success: function (data) { 
                    console.log("success"); 
                } 
            }); 
        } 
    } 
 
[Controller] 
 
public void Openingfile(string filename) 
        { 
            Process cmd = new Process(); 
            cmd.StartInfo.FileName = "cmd.exe"; 
            cmd.StartInfo.RedirectStandardInput = true; 
            cmd.StartInfo.RedirectStandardOutput = true; 
            cmd.StartInfo.RedirectStandardError = true; 
            cmd.StartInfo.CreateNoWindow = true; 
            cmd.StartInfo.UseShellExecute = false; 
            cmd.Start(); 
            cmd.StandardInput.WriteLine(filename); 
            cmd.StandardInput.Flush(); 
            cmd.StandardInput.Close(); 
        } 
 
For your convenience, we have prepared simple sample, it can be available in below location, please find it. 
 
 
Please let us know, if you have any other concerns. 
 
Regards, 
Ashokkumar B. 



AN Anis May 4, 2017 03:34 PM UTC

Hi,
thank you for your reply, but this doesn't work (no results in case of double-click on the file or click on open in the menu).

Regards,
Anis


AB Ashokkumar Balasubramanian Syncfusion Team May 5, 2017 02:30 PM UTC

Hi Anis, 
 
We have checked the reported issue in our end and we suspect this issue occurs due to path formation was mismatching in beforeOpen event. So please ensure your end the formatted filename was like below.   
 
Corresponding Line: var filename = args. model.selectedFolder + args.model.selectedItems[0];  
 
Proper: \\172.16.100.60\Anis\FileExplorer\FileBrowser\filename 
  
Improper: FileExplorer\FileBrowser\filename 
 
If still you are facing same problem, please provide the below information is more helpful to provide the solution to earlier. 
 
1.     If you are using this application in IIS or not 
2.     OS version 
3.     Visual Studio Configurations. 
 
Please let us know if you have any other concerns on this. 
 
Regards, 
Ashokkumar B. 



AN Anis May 5, 2017 03:16 PM UTC

Hi Ashokkumar,

the problem still exists.
- Yes I'm using IIS (v 7)
- Windows 7
- VS 2015, ASP.Net v4.6, MVC 5

Regards,
Anis


AB Ashokkumar Balasubramanian Syncfusion Team May 8, 2017 01:37 PM UTC

Hi Anis, 
 
Our previously provided solution will work only in the application hosted machine. When it be used with remote access or by using IIS, we can't access the global installed software on another machine. So the application was failed to invoke process with file location.  
 
Please check the below reference link. 
 
 
To resolve this problem, you can use our web components like ejPdfViewer, ejSpreadsheet, etc to access the corresponding files from IIS configuration. 
 
Regards, 
Ashokkumar B. 



AN Anis May 18, 2017 08:08 AM UTC

Hi,
I can open PDF format from FileExplorer in new browser tab:

@(Html.EJ().FileExplorer("fileExplorer")

               .FileTypes("*.png, *.gif, *.jpg, *.jpeg, *.docx, *.pdf, *.xlsx, *.zip, *.rar")

               .Layout(LayoutType.Tile)

               .Path(@Url.Content("~/FileExplorerContent/"))

               .AjaxAction(@Url.Action("FileActionDefault"))

               .Width("100%").Height("600")

               .IsResponsive(true)

               .MinWidth("350px")

               .ClientSideEvents(eve => eve.Create("onCreate").BeforeOpen("onBeforeOpen"))

            )

<script>

    function onCreate(args) {

        this._viewMenuObj.option({

            open: function (args) {

                this.enableItem("Open");

            }

        });

    }

    function onBeforeOpen(args) {

        if (args.itemType == "File" && !(/\.(bmp|dib|jpg|jpeg|jpe|jfif|gif|tif|tiff|png|ico)$/i).test(this._selectedFile)) {

            var file = args.model.selectedFolder.replace("~", "..") + args.model.selectedItems[0];

            window.open(file, args.model.selectedItems[0], '_blank', 'fullscreen=yes, menubar=yes, resizable=yes, titlebar=yes, toolbar=yes');

            args.cancel = true;

        }

    }

    function onclick() {

        $.ajax({

            url: '@Url.Action("RefreshFolders")',

            type: "POST",

            success: function (result) {

                //alert("ok");

            },

            error: function (result) {

                alert("error"+result);

            }

        });

    }

</script>   


How to open xls (excel) format using ejSpreadsheet?


Regards, 

Anis



BP Balamurugan P Syncfusion Team May 19, 2017 10:43 AM UTC

Hi Anis,  
  
Thanks for your update.  
  
We have checked your query and we would like to let you know that your requirement “To open xlsx (excel) format using Spreadsheet from FileExplorer” has been achieved.  Please refer the following code example.  
  
VIEW [INDEX.CSHTML]  
  
//…  
function onBeforeOpen(args) {  
    if (args.itemType == "File" && !(/\.(bmp|dib|jpg|jpeg|jpe|jfif|gif|tif|tiff|png|ico)$/i).test(this._selectedFile)) {  
        var file = args.model.selectedFolder.replace("~", "..") + args.model.selectedItems[0];  
        if (args.model.selectedItems[0].indexOf(".xlsx") > -1) //If it is excel file, action changed.  
            file = '@Url.Action("ViewInSpreadsheet")?filePath=' + file;  
        window.open(file, '_blank', 'fullscreen=yes, menubar=yes, resizable=yes, titlebar=yes, toolbar=yes');  
        args.cancel = true;  
    }  
}  
//…  
  
 
  
  
CONTROLLER [HOMECONTROLLER.CS]  
  
public ActionResult Index()  
{  
    return View();  
}  
  
public ActionResult ViewInSpreadsheet(string filePath)  
{  
    ViewData["FilePath"] = filePath;  
    return PartialView("_ViewInSpreadsheet", ViewData);  
}  
  
[AcceptVerbs(HttpVerbs.Post)]  
public ActionResult Import(ImportRequest importRequest)  
{  
    if (!String.IsNullOrEmpty(importRequest.Url))  
        importRequest.Url = Request.Url.AbsoluteUri.Replace(Request.Url.AbsolutePath, "") + importRequest.Url;  
    return importRequest.SpreadsheetActions();  
}  
  
 
  
  
PARTIALVIEW [_VIEWINSPREADSHEET.CSHTML]  
  
@(Html.EJ().Spreadsheet<object>("Spreadsheet")  
//...  
.ImportSettings(import =>  
{  
    import.ImportUrl((string)ViewData["FilePath"]);  
    import.ImportMapper("Import");  
})  
//...  
)  
  
 
  
  
Sample Link:   
  
Could you please check the above sample and get back to us if we misunderstood your requirement so that we can analyze based on that and provide you a better solution?  
 
 
Regards, 
Balamurugan P 



AN Anis May 22, 2017 08:41 AM UTC

Hi, 
Still one problem, how to save the spreadsheet file after the changes (save the file and not save as in computer)?

Regards,
Anis


AB Ashokkumar Balasubramanian Syncfusion Team May 23, 2017 09:05 AM UTC

Hi Anis,  
  
Thanks for your update.  
  
Your requirement “To save the spreadsheet file after the changes (save the file and not save as in computer)” has been achieved by using workbook instance ‘SaveAs()’ server-side method. Please refer the following code example.  
  
Method 1: Using Button click  
 
PARTIALVIEW [_VIEWINSPREADSHEET.CSHTML]  
  
<input type="button" id="saveSpreadsheet" value="Save Spreadsheet" />  
<input type="hidden" id="filePath" value="@ViewData["FilePath"]" />  
@(Html.EJ().Spreadsheet<object>("Spreadsheet")  
    //...  
)  
  
<script type="text/javascript">  
    $(function () {  
        $("#saveSpreadsheet").bind("click", function () {  
            var xlObj = $("#Spreadsheet").data("ejSpreadsheet"), saveFilePath = $("#filePath").val(), exportProps = xlObj.XLExport.getExportProps();  
  
            $.ajax({  
                type: "POST",  
                data: { sheetModel: exportProps.model, sheetData: exportProps.data, filePath: saveFilePath },  
                url: "/Home/SaveSpreadsheetOnBtnClick",  
                success: function (data) {  
                    alert(data);  
                }  
            });  
  
        });  
    });  
</script>  
  
  
  
CONTROLLER [HOMECONTROLLER.CS]  
  
[AcceptVerbs(HttpVerbs.Post)]  
public ActionResult SaveSpreadsheetOnBtnClick(string sheetModel, string sheetData, string filePath)  
{  
    MemoryStream ms = new MemoryStream();  
    filePath = Path.Combine(Server.MapPath(filePath));  
    Stream sData = Spreadsheet.Save(sheetModel, sheetData, ExportFormat.XLSX, ExcelVersion.Excel2013);  
    sData.Position = 0; //Reset stream position  
  
    ExcelEngine excelEngine = new ExcelEngine();  
    IApplication application = excelEngine.Excel;              
    IWorkbook workbook = application.Workbooks.Open(sData);  
    workbook.SaveAs(filePath);  
  
    return Content("File saved successfully!");  
}  
  
  
  
Method 2 - Using default Excel save action – ExportUrl()  
 
PARTIALVIEW [_VIEWINSPREADSHEET.CSHTML]  
  
<input type="hidden" id="filePath" value="@ViewData["FilePath"]" />  
@(Html.EJ().Spreadsheet<object>("Spreadsheet")  
    //...  
    .ExportSettings(export =>  
    {  
        export.ExcelUrl("SaveSpreadsheetToServer");  
        //...  
    })  
    .ClientSideEvents(eve => { eve.OnExport("onExport"); })  
)  
  
<script type="text/javascript">  
    function onExport(args) {  
        if (args.exportType == "Excel")  
            args.customParams["filePath"] = $("#filePath").val();  
    }  
</script>  
@Html.Raw(ViewData["message"])@*For alert message from server*@  
  
  
  
CONTROLLER [HOMECONTROLLER.CS]  
  
[AcceptVerbs(HttpVerbs.Post)]  
public ActionResult SaveSpreadsheetToServer(string sheetModel, string sheetData, string filePath)  
{  
    ViewData["FilePath"] = filePath;  
  
    MemoryStream ms = new MemoryStream();  
    filePath = Path.Combine(Server.MapPath(filePath));  
    Stream sData = Spreadsheet.Save(sheetModel, sheetData, ExportFormat.XLSX, ExcelVersion.Excel2013);  
    sData.Position = 0;//Reset stream position  
  
    ExcelEngine excelEngine = new ExcelEngine();  
    IApplication application = excelEngine.Excel;              
    IWorkbook workbook = application.Workbooks.Open(sData);  
    workbook.SaveAs(filePath);  
  
    ViewData["message"] = "<script language='javascript' type='text/javascript'>alert('File Saved successfully!');</script>";  
    return PartialView("_ViewInSpreadsheet", ViewData);  
}  
  
  
  
Sample Link: 
 
Please check the above sample and let us know whether this will fulfil your requirement, if not please share more information on this.  
 
Regards, 
Ashokkumar B. 



AN Anis May 25, 2017 10:42 AM UTC

Hi,
Neither method works for me, when I refresh all changes disappeare.
Help me please.

Regards,
Anis
 

Attachment: Files_8f4f48fa.rar


AB Ashokkumar Balasubramanian Syncfusion Team May 29, 2017 12:17 PM UTC

Hi Anis, 
 
We have analyzed the reported issue. But we are unable to reproduce it. For your reference, we have prepared a simple sample. In that sample, we have refresh the fileexplroer files. Please check the sample in below Location. 
 
 
If the issue persists, please revert us with detailed information of “Refreshfolders method Controller part” or else revert back the provided sample with the issue and replication procedure. This will be helpful to us assist you. 
 
Regards, 
Ashokkumar B. 



JB Julien Breton May 15, 2018 02:11 PM UTC

Hi,
Can we do the same things with word file like .docx?
Open and edit and save ?
Thanks


PR Piramanayagam Ramakrishnan Syncfusion Team May 16, 2018 02:08 PM UTC

Hi Julien, 
 
Yes. You can do same thing for docx files. We have already discussed this kind of things in the below forum,  
 
To know more about saving file operation in RTE component, please refer to below help document, 
 
Regards, 
Piramanayagam R. 


Loader.
Live Chat Icon For mobile
Up arrow icon