How to open a .js file from c# winform? I tried this
Process.Start(#"C:\...\software.exe", #"C:\...\mergescripts.js");
but it's not working. Manually, I can load the mergescripts.js file into my on software.exe using open file. But how to do it dynamically using button event from c#?
JintEngine can be used to execute JavaScript:
using (FileStream fs = new FileStream("file.js", FileMode.Open))
{
JintEngine js = JintEngine.Load(fs);
object result = js.Run("return status;");
Console.WriteLine(result);
}
please try with below syntax
ProcessStartInfo ps = new ProcessStartInfo();
ps.FileName = #"C:\Program Files (x86)\Notepad++\notepad++.exe";
ps.Arguments = #"C:\Users\Desktop\aaa.txt";
Process.Start(ps);
Related
I'm trying to read a xlsx file in html using javaScript but it seems my code is not so right as it should be.
I'm using this code:
<script>
function openRead(){
var excel = activeXObject("Excel.Application");
excel.visible = false;
var file = exel.workbooks.open("C:\Users\Utilizador\Desktop\teste.xlsx").activeSheet.cell(1,1).value;
var div = document.getElementById("div1").text;
div = file;
}
</script>
Getting the following error
activeXObject is not defined
I hope you guys can point me to the right direction!
ActiveXObject is available only on IE browser. So every other useragent will throw an error
https://stackoverflow.com/a/11101655/1172872
You can try existing libraries... (or see how they implemented it)
http://sheetjs.com/ (https://github.com/SheetJS/js-xlsx)
http://oss.sheetjs.com/js-xls/
I'm trying to upload a local file (C:\sample.txt) to my server. I have tried to implement this with Chrome web driver and its working absolutely fine.
But during implementing the same with HTMLUnitDriver, i couldn't browse the file item from my local disk. I tried the below two methods as well,
1) Send keys:
WebElement inputFile = driver.findElement(By.id("file"));
System.out.println(driver.getCurrentUrl());
LocalFileDetector detector = new LocalFileDetector();
String path = "C:\\UploadSample1.txt";
File f = detector.getLocalFile(path);
inputFile.sendKeys(f.getAbsolutePath());
2) Using a Robot:
WebElement browseFile = fluentWait(By.id("browseFile"), driver);
browseFile.click();
File file = new File("C:\\UploadSample1.txt");
driver.switchTo().activeElement();
StringSelection fileNameToWrite = new StringSelection(
file.getAbsolutePath());
Toolkit.getDefaultToolkit().getSystemClipboard()
.setContents(fileNameToWrite, null);
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
I need the file item to be browsed, then only i can save it to my server. Because just sending the file path will be searching the file in server disk. Now i'm really stuck and couldn't move further.
Any help is highly appreciated. Thankyou!
If you need to browse to the file first, that isn't possible IMHO; for that you will need AutoIT (as Robot class is not recommended). So your best bet would be sending file path using sendKeys.
formInput.setValueAttribute(formValue); worked fine for me.
Code snippet:
Iterator<String> formValueIterator = formValues.keySet().iterator();
while(formValueIterator.hasNext()){
String formKey = formValueIterator.next();
String formValue = formValues.get(formKey);
HtmlInput formInput = form.getInputByName(formKey);
if (formInput != null)
if (formInput instanceof HtmlPasswordInput) {
((HtmlPasswordInput)formInput).setValueAttribute(formValue);
} else {
formInput.setValueAttribute(formValue);
}
}
So I have a personal website, and I have a button that I want to use to open photoshop and run a script for me. How do I do this?
It is not possible. It would pose a huge security risk to allow javascript to open programs on client side.
This has been up for awhile, but if the solution to this in node is to use a child_process.
you can npm install child_process
and the code to run executables would be to do
const exec = require("child-process").execFile;
var process = exec("Photoshop.exe", [*add options here*], {cwd:"C:/*path to photoshop*"});
you can do a lot of cool things afterwards like event handlers
process.on("close", code => {
console.log("process closed with code: "+ code)
})
process.on("exit", code => {
console.log("process exited with code: "+ code)
})
process.stdout.on("data", data => {
console.log(data)
})
You can read the Docs here: https://nodejs.org/api/child_process.html
maybe this
Code will open image in photoshop with the help of javascript. You just need to place your image file into photoshop->sample folder nothing more than that and you done with it.
var fileRef = new File(app.path.toString() + “/Samples/test.jpg”); // ‘samples’ is a folder resides in Program Files\Adobe\Adobe Photoshop CS5\samples
//open (fileRef);
var doc = open(fileRef);
// get document name (and remove file extension)
var name = tempName[0];
// convert to RGB; convert to 8-bpc; merge visible
doc.changeMode(ChangeMode.RGB);
doc.bitsPerChannel = BitsPerChannelType.EIGHT;
doc.artLayers.add();
doc.mergeVisibleLayers();
// rename layer; duplicate to new document
var layer = doc.activeLayer;
layer.name = tempName[0];
layer.duplicate(newDoc, ElementPlacement.PLACEATBEGINNING);
// close imported document
doc.close(SaveOptions.DONOTSAVECHANGES);
When I use download() in CasperJS, I get a file saved in the system, but the file doesn't contain the actual source code of the webpage. It just contains a link to the remote page. How can I dump the source code of webpage into a local file using CasperJs? getHTML() is also only echoing the contents onto the terminal. How to save the contents to a file?
First import file system library
var fs = require('fs');
Extract html
var html = this.getHTML();
// or
var html = this.getPageContent();
Copy into a file
var f = fs.open('/path/to/your/file', 'w');
f.write(html);
f.close();
do just: fs.write('path/to/file', 'your string', 'w');
in this case you don't need open and close a file
I am trying to create a file on the local machine which captures the var file in javascript.
<script>
function button_click()
{
var file = GetFile('Getdoc'.aspx');
WriteToFile();
}
function WriteToFile() {
var fso, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
s = fso.CreateTextFile("C:\\Test\\Logfile.txt");
s.Write(file1);
s.Close();
}
</script>
Here we get a httpresponse stream which contains data in bytes into var file.
If I could find some help on this would be appreciated.
Thank you.
If I understand you correctly, you are encountering a problem when you are trying to write a file using ActiveXObject on IE? There is two things wrong with your script.
var file = GetFile('Getdoc'.aspx'); should be var file = GetFile('Getdoc.aspx');
You do not have file1 defined, so it is writing nothing to the file.
You need to keep in mind that most versions of IE have this functionality disabled due to the huge security risk that this poses.