This is a migrated thread and some comments may be shown as answers.

how to save xlsx to the server?

3 Answers 522 Views
Spreadsheet
This is a migrated thread and some comments may be shown as answers.
Vincent
Top achievements
Rank 1
Iron
Vincent asked on 31 Dec 2019, 02:54 AM

I want to export the current sheet to xlsx and send it to the server. I use excel proxy to send the file to server. but when the server side process done. the ui will auto refresh. I want to receive the return value and not refresh the UI, how can I do this, please help.

 

server side code:

[HttpPost]
        public ActionResult Post()
        {
            try
            {
                var data = Request.Form;
                var file = data["base64"][0];
                var fileName = data["fileName"][0];
                var contentType = data["contentType"][0];
                byte[] buffer = Convert.FromBase64String(file);
                string filePath = FileHelper.MapPath("/wwwroot/UserUpload/" + fileName);
                FileStream fs = new FileStream(filePath, FileMode.CreateNew);
                fs.Write(buffer, 0, buffer.Length);
                fs.Close();
                return new JsonResult("OK");
            }
            catch (Exception e)
            {
                return new JsonResult("Fail");
            }
        }

3 Answers, 1 is accepted

Sort by
0
Veselin Tsvetanov
Telerik team
answered on 02 Jan 2020, 11:27 AM

Hello Vincent,

I am ton completely sure that I correctly understand what would you mean by "I want to receive the return value". If you would like to receive the exported file on the client, you should return the file from the server call, as shown on our demos:

[HttpPost]
public ActionResult Index_Save(string contentType, string base64, string fileName)
{
    var fileContents = Convert.FromBase64String(base64);

    return File(fileContents, contentType, fileName);
}

If the above does not cover the scenario in question, please explain a bit in detail what you would like to achieve.

Regards,
Veselin Tsvetanov
Progress Telerik

Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
0
Vincent
Top achievements
Rank 1
Iron
answered on 02 Jan 2020, 02:09 PM

thank you for your reply. 

I do not want to client side download excel file. I just want to post the file to the server and save file to server, when save file success, return "OK" to client. client side receive the "OK" or "Fail" and do not refresh the page. like ...ajax post.

0
Veselin Tsvetanov
Telerik team
answered on 07 Jan 2020, 10:27 AM

Hello Vincent,

The request that is being sent to the proxy action is in fact a submitted <form> (Form Data request). Unless a file is returned from that action, it will always result in UI refresh/navigation. I am afraid I cannot think of an approach that would allow you to return no file and prevent the UI refresh. 

Regards,
Veselin Tsvetanov
Progress Telerik

Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
Tags
Spreadsheet
Asked by
Vincent
Top achievements
Rank 1
Iron
Answers by
Veselin Tsvetanov
Telerik team
Vincent
Top achievements
Rank 1
Iron
Share this question
or