spreadsheet,import mapper,sublime

hi
how can we avoid a post request on "http://js.syncfusion.com/demos/ejservices/api/Spreadsheet/Import " in import mapper . instead of the this can the ftp protocol be used .

1 Reply

SI Silambarasan I Syncfusion Team October 24, 2017 08:51 AM UTC

Hi Sumaira, 
 
Thank you for using Syncfusion products. 
 
We have checked your query and we would like to let you know that, we couldn’t import the file into Spreadsheet without using POST request since we need to convert the file data to spreadsheet data in server-side.  However, we have prepared a sample to demonstrate “To import file from ftp server to Spreadsheet” and the same can be downloaded from the below sample link.  Please refer the following code example. 
 
 
HTML 
 
<div id="Spreadsheet"></div> 
 
//... 
 
$("#Spreadsheet").ejSpreadsheet({ 
    importSettings: { 
        importOnLoad: true, 
        importMapper: "api/SpreadSheet/FtpImport" 
    } 
}); 
 
 
 
C# 
 
[AcceptVerbs("Post")] 
[OperationContract] 
[WebGet(BodyStyle = WebMessageBodyStyle.Bare)] 
public HttpResponseMessage FtpImport() 
{ 
    string fileName = "sample.xlsx"; 
 
    //FTP Server URL 
    string ftp = "ftp://ftpserver.com/"; 
 
    try 
    { 
        //Create FTP Request 
        FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftp + fileName); 
        request.Method = WebRequestMethods.Ftp.DownloadFile; 
        //Enter the FTP Server credentials 
        request.Credentials = new NetworkCredential("Username", "Password"); 
 
        //Fetch the Response and read it into a MemoryStream object. 
        ImportRequest importRequest = new ImportRequest(); 
        importRequest.FileStream = new MemoryStream(); 
 
        FtpWebResponse response = (FtpWebResponse)request.GetResponse(); 
 
        response.GetResponseStream().CopyTo(importRequest.FileStream); 
 
        //Reset stream reader position 
        importRequest.FileStream.Position = 0; 
 
        string spreadsheetData = Spreadsheet.Open(importRequest); 
        return new HttpResponseMessage() { Content = new StringContent(spreadsheetData, Encoding.UTF8, "text/plain") }; 
 
    } 
    catch (WebException ex) 
    { 
        throw new Exception((ex.Response as FtpWebResponse).StatusDescription); 
    } 
} 
 
 
 
Could you please check the above sample and get back to us if we misunderstood your requirement or if you need any further assistance on this. 
 
Regards, 
Silambarasan 


Loader.
Up arrow icon