Guest User

Untitled

a guest
Dec 10th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. // Reads a file into memory stream. Common for all trials below
  2. memoryStream = ReadDataIntoMemoryStream();
  3.  
  4. // TRIAL 1
  5. FileStream fs= new FileStream();
  6. memoryStream.CopyTo(fs);
  7.  
  8. string mimeType = "application/vnd.openxmlformats-
  9. officedocument.spreadsheetml.sheet";
  10.  
  11. return File(fs, mimeType);
  12.  
  13. // TRIAL 2
  14. string mimeType = "application/vnd.openxmlformats-
  15. officedocument.spreadsheetml.sheet";
  16. byte[] fileBytes = memoryStream.ToArray();
  17. return File(fileBytes, mimeType);
  18.  
  19. // TRIAL 3
  20. string filepath = ".......filename.xlsx"; // actual physical file on
  21. // the server
  22. return Content(filepath);
  23.  
  24. $(document).ready(function () {
  25. $('#777').on('click', function () {
  26. $.ajax({
  27. method: "GET",
  28. url: "Report/createFile",
  29. contentType: "application/download", // not needed for Trial 3
  30. // where string is returned
  31. dataType:"text",
  32. success: function (data) {
  33. // window.location.href = data; // THIS WORKS with TRIAL 3
  34. // where filepath is returned
  35. },
  36. error: function (data) {
  37. alert("Error.");
  38. },
  39. });
  40. });
  41. });
Add Comment
Please, Sign In to add comment