Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getfile(filetype) {
- var SurveyId = $('#SurveyID').val();
- var url = '/Survey/GetSurveyFile';
- $.ajax({
- type: 'GET',
- url: url,
- data: { survey: SurveyId, surveyFileType: filetype },
- success: function (result) {
- // ?
- },
- error: function (result) {
- // handle errors
- location.href = "/Home/"
- }
- });
- }
- public FileResult GetSurveyFile(string survey, string surveyFileType)
- {
- try
- {
- var tmpSurvey = EntityModelDataProvider.GetSurveyByID(int.Parse(survey));
- var tmpSurveyFileTypes = EntityModelDataProvider.GetSurveyFileTypes();
- var tmpSurveyFileType = tmpSurveyFileTypes.FirstOrDefault(_sft => _sft.SurveyFile_Type_Id == int.Parse(surveyFileType));
- var tmpFile = EntityModelDataProvider.GetSurveyFilesBySurveyAndType(tmpSurvey.Survey_PK, tmpSurveyFileType.SurveyFile_Type_PK);
- if (tmpFile != null)
- {
- byte[] fileBytes = tmpFile.SurveyFile;
- string fileName = tmpFile.SurveyFile_Name;
- return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);
- }
- else
- throw new Exception("File not found!");
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- function getfile() {
- $.ajax({
- type: 'get',
- url: '@Url.Action("Download")',
- success: function () {
- window.location = '@Url.Action("Download")';
- }
- });
- }
- $(function() {
- $('h2').on('click', getfile);
- });
- public FileResult Download()
- {
- var bytes = System.IO.File.ReadAllBytes(Server.MapPath("~/123.txt"));
- return File(bytes, System.Net.Mime.MediaTypeNames.Application.Octet, "123.txt");
- }
- function getfile() {
- var p1 = Math.random().toString();
- var p2 = Math.floor(Math.random() * 100);
- window.location = '@Url.Action("Download")?' + 'p1=' + p1 + '&' + 'p2=' + p2;
- }
- $(function() {
- $('h2').on('click', getfile);
- });
- public FileResult Download(string p1, int p2)
- {
- var bytes = System.IO.File.ReadAllBytes(Server.MapPath("~/123.txt"));
- return File(bytes, System.Net.Mime.MediaTypeNames.Application.Octet, string.Format("123_{0}_{1}.txt", p1, p2));
- }
- var result = $("input[id*='filelabel_']").filter(function () {
- return this.id.match(/filelabel_d+$/);
- }).length;
- $("input[id*='file_input_']").each(function (i, el) {
- result = result - 1;
- var inputId = el.id;//getting textbox id
- if ($("#" + inputId).val()!=null) {
- var inputtext = $("#" + inputId).val();
- if (inputId != "input") {
- var fid = inputId.substring(0, inputId.indexOf("_"));//t.substr(t.indexOf("_") + 1);
- }
- var lastindex = inputId.lastIndexOf("_");
- var id = inputId.substring(lastindex + 1);
- var mainlabel = $("#filelabel_" + id).text();
- var data = new FormData();
- var files = $(".FilePhoto").get(0).files;
- if (files.length > 0) {
- data.append("HelpSectionImages", files[0]);
- }
- else {
- }
- //var fileUpload = $("#" + inputId).get(0);
- //var files = fileUpload.files;
- //alert(files);
- //datav.push({ file: files });
- datav.push({ CId: fid, CLabel: mainlabel, CValue: inputtext, CControlType: "File", COption: null});
- }
- });
- //var result = $("label[id*='filelabel_']").filter(function () {
- // return this.id.match(/filelabel_d+$/);
- //}).length;
- //$("label[id*='filelabel_']").each(function (i, el) {
- // result = result - 1;
- // var inputId = el.id;//getting textbox id
- // if ($("#" + inputId).val()!="") {
- // var inputtext = $("#" + inputId).val();
- // if (inputId != "input") {
- // var fid = inputId.substring(0, inputId.indexOf("_"));//t.substr(t.indexOf("_") + 1);
- // }
- // var lastindex = inputId.lastIndexOf("_");
- // var id = inputId.substring(lastindex + 1);
- // var mainlabel = $("#label_" + id).text();
- // datav.push({ CId: fid, CLabel: mainlabel, CValue: inputtext, CControlType: "File", COption: null });
- // }
- // //result = result - 1;
- // //var labelId = el.id;
- // //var mainlabeltext = $("#" + labelId).text();
- // //var lastindex = labelId.lastIndexOf("_");
- // ////var lastid = labelId.substring(lastindex + 1);
- // //var lastid = lastindex + 1;
- // //var req = $("#hd" + labelId).val();
- // //if (req == undefined) {
- // // req = 0;
- // //}
- // //if (result >= 0) {
- // // datav.push({ CSeq: lastid, CLabel: mainlabeltext, CValue: null, CControlType: "File", COption: null, CRequired: req });
- // //}
- //});
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement