Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.81 KB | None | 0 0
  1. function getfile(filetype) {
  2. var SurveyId = $('#SurveyID').val();
  3. var url = '/Survey/GetSurveyFile';
  4. $.ajax({
  5. type: 'GET',
  6. url: url,
  7. data: { survey: SurveyId, surveyFileType: filetype },
  8. success: function (result) {
  9. // ?
  10. },
  11. error: function (result) {
  12. // handle errors
  13. location.href = "/Home/"
  14. }
  15. });
  16. }
  17.  
  18. public FileResult GetSurveyFile(string survey, string surveyFileType)
  19. {
  20. try
  21. {
  22. var tmpSurvey = EntityModelDataProvider.GetSurveyByID(int.Parse(survey));
  23. var tmpSurveyFileTypes = EntityModelDataProvider.GetSurveyFileTypes();
  24. var tmpSurveyFileType = tmpSurveyFileTypes.FirstOrDefault(_sft => _sft.SurveyFile_Type_Id == int.Parse(surveyFileType));
  25. var tmpFile = EntityModelDataProvider.GetSurveyFilesBySurveyAndType(tmpSurvey.Survey_PK, tmpSurveyFileType.SurveyFile_Type_PK);
  26. if (tmpFile != null)
  27. {
  28. byte[] fileBytes = tmpFile.SurveyFile;
  29. string fileName = tmpFile.SurveyFile_Name;
  30. return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);
  31. }
  32. else
  33. throw new Exception("File not found!");
  34. }
  35. catch (Exception ex)
  36. {
  37.  
  38. throw ex;
  39. }
  40. }
  41.  
  42. function getfile() {
  43. $.ajax({
  44. type: 'get',
  45. url: '@Url.Action("Download")',
  46. success: function () {
  47. window.location = '@Url.Action("Download")';
  48. }
  49. });
  50. }
  51.  
  52. $(function() {
  53. $('h2').on('click', getfile);
  54. });
  55.  
  56.  
  57. public FileResult Download()
  58. {
  59. var bytes = System.IO.File.ReadAllBytes(Server.MapPath("~/123.txt"));
  60. return File(bytes, System.Net.Mime.MediaTypeNames.Application.Octet, "123.txt");
  61. }
  62.  
  63. function getfile() {
  64. var p1 = Math.random().toString();
  65. var p2 = Math.floor(Math.random() * 100);
  66.  
  67. window.location = '@Url.Action("Download")?' + 'p1=' + p1 + '&' + 'p2=' + p2;
  68. }
  69.  
  70. $(function() {
  71. $('h2').on('click', getfile);
  72. });
  73.  
  74.  
  75. public FileResult Download(string p1, int p2)
  76. {
  77. var bytes = System.IO.File.ReadAllBytes(Server.MapPath("~/123.txt"));
  78. return File(bytes, System.Net.Mime.MediaTypeNames.Application.Octet, string.Format("123_{0}_{1}.txt", p1, p2));
  79. }
  80.  
  81. var result = $("input[id*='filelabel_']").filter(function () {
  82. return this.id.match(/filelabel_d+$/);
  83. }).length;
  84.  
  85. $("input[id*='file_input_']").each(function (i, el) {
  86. result = result - 1;
  87. var inputId = el.id;//getting textbox id
  88. if ($("#" + inputId).val()!=null) {
  89. var inputtext = $("#" + inputId).val();
  90. if (inputId != "input") {
  91. var fid = inputId.substring(0, inputId.indexOf("_"));//t.substr(t.indexOf("_") + 1);
  92. }
  93. var lastindex = inputId.lastIndexOf("_");
  94. var id = inputId.substring(lastindex + 1);
  95. var mainlabel = $("#filelabel_" + id).text();
  96. var data = new FormData();
  97. var files = $(".FilePhoto").get(0).files;
  98. if (files.length > 0) {
  99. data.append("HelpSectionImages", files[0]);
  100. }
  101. else {
  102.  
  103. }
  104.  
  105. //var fileUpload = $("#" + inputId).get(0);
  106. //var files = fileUpload.files;
  107. //alert(files);
  108. //datav.push({ file: files });
  109. datav.push({ CId: fid, CLabel: mainlabel, CValue: inputtext, CControlType: "File", COption: null});
  110. }
  111. });
  112.  
  113. //var result = $("label[id*='filelabel_']").filter(function () {
  114. // return this.id.match(/filelabel_d+$/);
  115. //}).length;
  116.  
  117. //$("label[id*='filelabel_']").each(function (i, el) {
  118. // result = result - 1;
  119.  
  120. // var inputId = el.id;//getting textbox id
  121.  
  122. // if ($("#" + inputId).val()!="") {
  123.  
  124. // var inputtext = $("#" + inputId).val();
  125.  
  126. // if (inputId != "input") {
  127. // var fid = inputId.substring(0, inputId.indexOf("_"));//t.substr(t.indexOf("_") + 1);
  128. // }
  129.  
  130. // var lastindex = inputId.lastIndexOf("_");
  131. // var id = inputId.substring(lastindex + 1);
  132.  
  133. // var mainlabel = $("#label_" + id).text();
  134.  
  135. // datav.push({ CId: fid, CLabel: mainlabel, CValue: inputtext, CControlType: "File", COption: null });
  136.  
  137. // }
  138. // //result = result - 1;
  139.  
  140. // //var labelId = el.id;
  141. // //var mainlabeltext = $("#" + labelId).text();
  142. // //var lastindex = labelId.lastIndexOf("_");
  143. // ////var lastid = labelId.substring(lastindex + 1);
  144. // //var lastid = lastindex + 1;
  145. // //var req = $("#hd" + labelId).val();
  146. // //if (req == undefined) {
  147. // // req = 0;
  148. // //}
  149.  
  150. // //if (result >= 0) {
  151. // // datav.push({ CSeq: lastid, CLabel: mainlabeltext, CValue: null, CControlType: "File", COption: null, CRequired: req });
  152. // //}
  153.  
  154. //});
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement