Getting error for variable does not exist in current context cshtml? - asp.net-mvc-4

i have following code for getting error
$('#Template').click(function () {
var selectedTempleteType = $('#BulkLoadActionDropDownId option:selected').val();
var path = '#Url.Content("~/Upload/DownloadBulkLoadActionTemplate?templateType=" + selectedTempleteType)';
$(this).attr("href", path);
});
error showing for "selectedTempleteType".

selectedTempleteType is a client-side JS variable, you cannot use it inside #Url.Content() which runs server-side (and #Url.Content() is incorrect to map URL path with query string, use #Url.Action() instead). You should change from this:
var path = '#Url.Content("~/Upload/DownloadBulkLoadActionTemplate?templateType=" + selectedTempleteType)';
to this one:
var path = '#Url.Action("DownloadBulkLoadActionTemplate", "Upload")?templateType=' + selectedTempleteType;
Or using placeholder inside #Url.Action() with replace() in client-side:
var path = '#Url.Action("DownloadBulkLoadActionTemplate", "Upload", new { templateType = "xxxx" })';
path = path.replace("xxxx", selectedTempleteType);

Related

How to get request body in angular from ActivatedRoute

As i can get the query params by using ActivatedRoute which is get request. but how can i get request body by using ActivatedRoute from post request. If ActivatedRoute is not right option to get then how should i get request body
This is my jsp code:-
var res = "url which i am creating";
var url =res[0];
var mapForm = document.createElement("form");
mapForm.target = "Test";
mapForm.method = "post";
mapForm.action = url;
//Splitting parameters from url to add into body
var res1 =res[1].split("=");
var name = res1[0];
var value = res1[1];
mapInput3 = document.createElement("input");
mapInput3.type = "hidden";
mapInput3.name =name;
mapInput3.value = value;
mapForm.appendChild(mapInput3);
document.body.appendChild(mapForm);
map = window.open("", "Test", "menubar,
toolbar, location, directories, status, scrollbars,
resizable, dependent, width=1200, height=600,
left=0,top=0");
if (map) {
mapForm.submit();
}
this is my angular code:-
this.activeRoute.queryParams.subscribe(params => {
this.authKey = params['auth_key'];
});
Now if I sent parameter through get method from jsp, I am able to get it from above angular code.
but if i sent params through post method then i get message as " Cannot post"
If I got you right you want to get the body of the query.
You can use snapshot.get and when declare a it with a value something like this ->
const t = this.route.snapshot.mapedQuery.get()
The value of- t is your query body.
Answered from my phone so I can’t format the code

How to correctly get gulp.src globs from a variable?

Given the following Gulp setup
const { src, dest } = require('gulp');
var zip = require('gulp-zip');
var pkgDist = 'packages/';
function pkg(done) {
src(['./**', '!node_modules/**', '!vendor/**', '!.gitignore', '!*.json', '!*.lock'], {base: '..'})
.pipe(zip('archive.zip'))
.pipe(dest(pkgDist))
done();
};
exports.pkg = pkg;
how can I modify it in order to get src globs from a variable, i.e. pkgSrc, something like this:
[...]
var pkgSrc = <what to put here?>;
[...]
src(pkgSrc)
[...]
I've tried to use this var pkgSrc = " ['./**', '!node_modules/**', '!vendor/**', '!.gitignore', '!*.json', '!*.lock'], {base: '..'} "; but it doesn't work.
If it's easier, I'm also open to solutions that result into this src([pkgSrc], {base: '..'})
You can go with just:
var pkgSrc = ['./**', '!node_modules/**', '!vendor/**', '!.gitignore', '!*.json', '!*.lock']
gulp.src first argument can be a string or an array, so now it is an array above.
The second argument is an object of options. Include the options sepearately: {base: '..'} so
src(pkgSrc, {base: '..'})

Pentaho - upload file using API

I need to upload a file using an API.
I tried REST CLIENT and didn't find any options.
Tried with HTTP POST and that responded with 415.
Please suggest how to accomplish this
Error 415 is “Unsupported media type”.
You may need to change the media type of the request or check whether that type of file us accepted by the remote server.
https://en.m.wikipedia.org/wiki/List_of_HTTP_status_codes
This solution uses only standard classes of jre 7. Add a step Modified Java Script Value in your transformation. You will have to add two columns in the flow: URL_FORM_POST_MULTIPART_COLUMN and FILE_URL_COLUMN, you can add as many files as you want, you will just have to call outputStreamToRequestBody.write more times.
try
{
//in this step you will need to add two columns from the previous flow -> URL_FORM_POST_MULTIPART_COLUMN, FILE_URL_COLUMN
var serverUrl = new java.net.URL(URL_FORM_POST_MULTIPART_COLUMN);
var boundaryString = "999aaa000zzz09za";
var openBoundary = java.lang.String.format("\n\n--%s\nContent-Disposition: form-data\nContent-Type: text/xml\n\n" , boundaryString);
var closeBoundary = java.lang.String.format("\n\n--%s--\n", boundaryString);
// var netIPSocketAddress = java.net.InetSocketAddress("127.0.0.1", 8888);
// var proxy = java.net.Proxy(java.net.Proxy.Type.HTTP , netIPSocketAddress);
// var urlConnection = serverUrl.openConnection(proxy);
var urlConnection = serverUrl.openConnection();
urlConnection.setDoOutput(true); // Indicate that we want to write to the HTTP request body
urlConnection.setRequestMethod("POST");
//urlConnection.addRequestProperty("Authorization", "Basic " + Authorization);
urlConnection.addRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundaryString);
var outputStreamToRequestBody = urlConnection.getOutputStream();
outputStreamToRequestBody.write(openBoundary.getBytes(java.nio.charset.StandardCharsets.UTF_8));
outputStreamToRequestBody.write(java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(FILE_URL_COLUMN)));
outputStreamToRequestBody.write(closeBoundary.getBytes(java.nio.charset.StandardCharsets.UTF_8));
outputStreamToRequestBody.flush();
var httpResponseReader = new java.io.BufferedReader(new java.io.InputStreamReader(urlConnection.getInputStream()));
var lineRead = "";
var finalText = "";
while((lineRead = httpResponseReader.readLine()) != null) {
finalText += lineRead;
}
var status = urlConnection.getResponseCode();
var result = finalText;
var time = new Date();
}
catch(e)
{
Alert(e);
}
I solved this by using the solution from http://www.dietz-solutions.com/2017/06/pentaho-data-integration-multi-part.html
Thanks Ben.
He's written a Java class for Multi-part Form submission. I extendd by adding a header for Authorization...

Script for File upload in google drive - Error encountered: An unexpected error occurred

I use a script to upload document into google spreadsheet and automatically put link to it into current cell. Since yesterday all was gone fine, but since this morning i receive this generic error:
https://docs.google.com
Error encountered: An unexpected error occurred
This is the code:
// upload document into google spreadsheet
// and put link to it into current cell
function onOpen(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet()
var menuEntries = [];
menuEntries.push({name: "Accedi al modulo per allegare un file...", functionName: "doGet"});
ss.addMenu("Carica scheda di rilevazione dati...", menuEntries);
}
function doGet(e) {
var app = UiApp.createApplication().setTitle("FORM per il caricamento della scheda di rilevazione dati");
SpreadsheetApp.getActiveSpreadsheet().show(app);
var form = app.createFormPanel().setId('frm').setEncoding('multipart/form-data');
var formContent = app.createVerticalPanel();
form.add(formContent);
formContent.add(app.createFileUpload().setName('thefile'));
// these parameters need to be passed by form
// in doPost() these cannot be found out anymore
formContent.add(app.createHidden("activeCell", SpreadsheetApp.getActiveRange().getA1Notation()));
formContent.add(app.createHidden("activeSheet", SpreadsheetApp.getActiveSheet().getName()));
formContent.add(app.createHidden("activeSpreadsheet", SpreadsheetApp.getActiveSpreadsheet().getId()));
formContent.add(app.createSubmitButton('Invia ed archivia scheda'));
app.add(form);
SpreadsheetApp.getActiveSpreadsheet().show(app);
return app;
}
function doPost(e) {
var app = UiApp.getActiveApplication();
app.createLabel('sto salvando...');
var fileBlob = e.parameter.thefile;
var doc = DocsList.getFolderById('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').createFile(fileBlob);
var label = app.createLabel('file caricato con successo');
// write value into current cell
var value = 'hyperlink("' + doc.getUrl() + '";"' + doc.getName() + '")'
var activeSpreadsheet = e.parameter.activeSpreadsheet;
var activeSheet = e.parameter.activeSheet;
var activeCell = e.parameter.activeCell;
var label = app.createLabel('file memorizzato correttamente');
app.add(label);
SpreadsheetApp.openById(activeSpreadsheet).getSheetByName(activeSheet).getRange(activeCell).setFormula(value);
app.close();
return app;
}
According to Your Question
Since yesterday all was gone fine, but since this morning i receive this generic error: https://docs.google.com Error encountered: An unexpected error occurred
According to Google developers page
So, I think problem may be in
var doc = DocsList.getFolderById('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').createFile(fileBlob);
try to use DriveApp instead of DocList. more info

How to get output of a webpage in ActionScript 2

For Actionscript 2.0
Let's say this page
www.example.com/mypage
returns some html that I want to parse in Actionscript.
How do i call this page from Actionscript while getting back the response in a string variable?
use LoadVars():
var lv = new LoadVars();
//if you want to pass some variables, then:
lv.var1 = "BUTTON";
lv.var2 = "1";
lv.sendAndLoad("http://www.example.com/mypage.html", lv, "POST");
lv.onLoad = loadedDotNetVars;
function loadedDotNetVars(success)
{
if(success)
{
// operation was a success
trace(lv.varnameGotFromPage)
}
else
{
// operation failed
}
}
//if you dont want to send data, just get from it, then use just lv.Load(...) instead of sendAndLoad(...)
I understand. Use this code then:
docXML = new XML(msg);
XMLDrop = docXML.childNodes;
XMLSubDrop = XMLDrop[0].childNodes;
_root.rem_x = (parseInt(XMLSubDrop[0].firstChild));
_root.rem_y = (parseInt(XMLSubDrop[1].firstChild));
_root.rem_name = (XMLSubDrop[2].firstChild);
var htmlFetcher:LoadVars = new LoadVars();
htmlFetcher.onData = function(thedata) {
trace(thedata); //thedata is the html code
};
Use:
htmlFetcher.load("http://www.example.com/mypage");
to call.
I suppose you could use:
page = getURL("www.example.com/mypage.html");
And it would load the page contents on the page variable.