Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Reads a file into memory stream. Common for all trials below
- memoryStream = ReadDataIntoMemoryStream();
- // TRIAL 1
- FileStream fs= new FileStream();
- memoryStream.CopyTo(fs);
- string mimeType = "application/vnd.openxmlformats-
- officedocument.spreadsheetml.sheet";
- return File(fs, mimeType);
- // TRIAL 2
- string mimeType = "application/vnd.openxmlformats-
- officedocument.spreadsheetml.sheet";
- byte[] fileBytes = memoryStream.ToArray();
- return File(fileBytes, mimeType);
- // TRIAL 3
- string filepath = ".......filename.xlsx"; // actual physical file on
- // the server
- return Content(filepath);
- $(document).ready(function () {
- $('#777').on('click', function () {
- $.ajax({
- method: "GET",
- url: "Report/createFile",
- contentType: "application/download", // not needed for Trial 3
- // where string is returned
- dataType:"text",
- success: function (data) {
- // window.location.href = data; // THIS WORKS with TRIAL 3
- // where filepath is returned
- },
- error: function (data) {
- alert("Error.");
- },
- });
- });
- });
Add Comment
Please, Sign In to add comment