Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. string FilePath = HttpContext.Current.Server.MapPath("~/FILENAME.txt");
  2. string FileContent = "";
  3. FileContent += "Text Here" + Environment.NewLine;
  4. File.WriteAllText(FilePath, FileContent);
  5.  
  6. byte[] fileBytes = System.IO.File.ReadAllBytes(FilePath);
  7.  
  8. string FilePath = HttpContext.Current.Server.MapPath("~/FILENAME.txt");
  9.  
  10. string FileContent = "";
  11.  
  12. FileContent += "Text Here" + Environment.NewLine;
  13.  
  14. File.WriteAllText(FilePath, FileContent);
  15.  
  16. var file = HttpContext.Current.Server.MapPath("~/FILENAME.txt");
  17.  
  18. HttpContext.Current.Response.AppendHeader("content-disposition", "attachment; filename=NewFile.txt");
  19.  
  20. HttpContext.Current.Response.ContentType = "application/octet-stream";
  21.  
  22. HttpContext.Current.Response.TransmitFile(file);
  23.  
  24. HttpContext.Current.Response.End();
  25.  
  26. $.ajax({
  27. url: "/api/WebService/spPOImportGenImportPOTxt/" + $("#ID").val(),
  28. type: "POST",
  29. contentType: "application/octet-stream; charset=utf-8",
  30. error: function(request, status, error) {
  31.  
  32. alert("Something went wrong: " + error);
  33.  
  34. $.unblockUI();
  35.  
  36. },
  37. success: function(data) {
  38.  
  39. alert("Data has been successfully saved.");
  40.  
  41. console.log(data);
  42.  
  43. $.unblockUI();
  44.  
  45. }
  46.  
  47. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement