I created a Windows 7 Gadget and I need to create a place on each user's computer to store the Settings.ini file (Created from my SettingsManager.js file). The application packaging team at my company recommends I use
%LOCALAPPDATA%\Microsoft\Windows Sidebar\
and then add
Gadgets\iMon.Gadget\
subfolders. This is so each user's settings are stored in a unique location and won't be changed by any other applications or gadgets.
Do I need to use something along the lines of
var fso = new ActiveXObject("Scripting.FileSystemObject");
var folder = fso.CreateFolder("path");
Any help on how to do this would be appreciated.
Update: I found how to get the %localappdata% path, but I still need to create the new folder. Here's what I've tried without success:
var wshshell = new ActiveXObject("wscript.shell");
var localAppData = wshshell.ExpandEnvironmentStrings("%localappdata%");
var filePath = localAppData + "\\Microsoft\\Windows Sidebar\\Gadgets\\iMon.Gadget";
var fso = new ActiveXObject("Scripting.FileSystemObject");
var filePath = localAppData + "\\Microsoft\\Windows Sidebar\\Gadgets\\iMon.Gadget";
I'm not sure I understand what you're trying to do here. is iMon.Gadget the name of your gadget? If so, this folder is automatically created for you upon installation of the gadget when the .gadget archive is executed. All the gadget's files and folders will be unpacked to
%LOCALAPPDATA\Microsoft\Windows Sidebar\Gadgets\iMon.gadget\
In your code, you can then proceed to manipulate files within this folder (and it's subfolders). To get the full path, you use
var gadgetPath = System.Gadget.path;
For example:
var oFile,
gadgetPath = System.Gadget.path,
oFSO = ActiveXObject("Scripting.FileSystemObject");
oFile = oFSO.CreateTextFile(gadgetPath + "\\test.txt", true);
oFile.WriteLine("Test.");
oFile.Close();
Related
I need to access list of files in "D//logs" folder from my machine using javascript.
And then display them as hyperlink in a html page. I tried to acheive this using ActiveX, but accessing files is throwing error.
(Developing only for Internet explorer)
var fso = new ActiveXObject("Scripting.FileSystemObject");
var xx = fso.GetFolder("d:\\logs");
var yy = new Enumerator(xx.Files);
var zz = new Enumerator(yy.item()); // how to acess files inside folder
My machine is connected with a scanner. The scanner can return a couple of images and I can get the paths of these images in the web page. Then I want to upload these images using Plupload plugin. Now I can get these file using ActiveX. But when I call the AddFile function, it doesn't work. It seems like the file returned by ActiveX is not suitable for the AddFile function. How can I do ?
//scanFilePath such as: D:\image001.jpg
var fso = new ActiveXObject("Scripting.FileSystemObject");
var f1 = fso.GetFile(scanFilePath);
var i_upload = $("#uploader").pluploadQueue();
var tmp = scanFilePath.split("\\");
var filename = tmp[tmp.length-1];
i_upload.addFile(f1, filename);
I have a problem regarding creating an XML file via a web browser and being able to read/write from it.
Multiple browsers have issues with this and I cant seem to find a solution that works.
I am creating a CMS which displays XML data in fields. I then want to read the values of those input elements and then overwrite the XML file using Javascript or JQuery.
The XML file will be stored on a web server and the client PC's will access the CMS via a webpage on the server and then reading/writing to the XML.
The Code below gives you an idea of what IM trying to do:
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
var fso = new ActiveXObject("Scripting.FileSystemObject");
var FILENAME ="xml.xml"; //<---- In Current Directory on Web server.
var file = fso.CreateTextFile(FILENAME, true);
file.WriteLine('<?xml version="1.0" encoding="utf-8"?>\n');
file.WriteLine('<Seating_Plan>\n');
var table = document.getElementById("table_assoc");
var rCount = table.rows.length;
for (var i = 1; i < rCount; i++) {
var id = table.rows[i].cells[0].children[0].value;
var deptcode = table.rows[i].cells[1].children[0].value;
var name = table.rows[i].cells[2].children[0].value;
var role = table.rows[i].cells[3].children[0].value;
var desc = table.rows[i].cells[4].children[0].value;
var image = table.rows[i].cells[5].children[0].value;
var asdir = table.rows[i].cells[6].children[0].value;
file.WriteLine('<Person id="' + id + '"><Dept>' + deptcode + '</Dept><Name>' + name + '</Name><Description>' + desc + '</Description><Role>' + role + '</Role><Image><image href="' + image + '"/></Image><AssociateDir><AssociateDir href="' + asdir + '"/></AssociateDir></Person>');
}
file.WriteLine('</Seating_Plan>');
file.Close();
}
However, This works only when accessing the webpage on a local system rather than the Server eg. via: "file://C:..." rather than:
http://localhost/admin.html
What is the best way to do this?
Any help would be appreciated.
Many thanks!
Aj
I suspect you're misunderstanding something here:
var fso = new ActiveXObject("Scripting.FileSystemObject");
var FILENAME ="xml.xml"; //<---- In Current Directory on Web server.
The web browser can't access the server's file system. That ActiveX object may allow file system access on the current host, but it's not going to allow it on other hosts. If there are no errors and the browser is allowing the ActiveX object to interact with the local file system then I'll bet it's successfully creating the file on the local file system. (In whatever happens to be the current working directory for the browser process, since no directory was specified.)
To interact with files on the server's file system you'll need to use server-side code.
I'm developing my own Thunderbird extension.
The extension adds an .xml-file as an attachment to a Thunderbird mail (it works very well).
My only problem is that I don’t know how to use a relative path.
It looks something like that:
var file= 'C:\\...[… \\…]...\\chrome\\VHitG2.xml';
var attachments = [];
attachments.push(FileToAttachment(file));
AddAttachments(attachments);
If the extension is installed in a different path, the extension can’t work.
Doe’s anyone know how to use relative paths ?
The FileToAttachment() function doesn't do magic, it is actually very simple. I assume that you are talking about a static file that is part of your extension - it should be accessible under a URL like chrome://myextension/content/VHitG2.xml. Then you can simply create an nsIMsgAttachment instance yourself using that URL:
var attachment = Components.classes["#mozilla.org/messengercompose/attachment;1"]
.createInstance(Components.interfaces.nsIMsgAttachment);
attachment.url = "chrome://myextension/content/VHitG2.xml";
AddAttachments([attachment]);
Note that your extension doesn't need to be installed unpacked for that, you don't need an actual file on disk.
I used a very circuitous way to get the URL of the extension’s files:
Components.utils.import("resource://gre/modules/FileUtils.jsm");
var test1 = FileUtils.getFile("CurProcD", ["VHitG2.xml"]);
var test2 = FileUtils.getFile("CurProcD", ["VHitG.xml"]);
var file1 = test1.path.replace(/VHitG2.xml/i, "extensions\\custom-toolbar-button#example.com\\chrome\\VHitG2.xml");
var file2 = test2.path.replace(/VHitG.xml/i, "extensions\\custom-toolbar-button#example.com\\chrome\\VHitG.xml");
var attachment1 = file1.replace(/\\/g, "\\\\");
var attachment2 = file2.replace(/\\/g, "\\\\");
After my first question here, I am now looking for a way do the the same, but instead of opening an EML as a message, I want to open it as a draft.
Basically, I want to load a generated EML file into the compose window, so I can directly send it.
I already found some code, but I can't find the correct documentation on how to use it
var filePath = new FileUtils.File(getPath(params));
var uri = io.newFileURI(filePath);
var msgComposeService = Components.classes["#mozilla.org/messengercompose;1"].getService(Components.interfaces.nsIMsgComposeService);
var messenger = Components.classes["#mozilla.org/messenger;1"].createInstance(Components.interfaces.nsIMessenger);
var hdr = messenger.msgHdrFromURI(uri.spec);
var identity = getIdentityForHeader(hdr, Components.interfaces.nsIMsgCompType.Draft);
var msgWindow = Components.classes["#mozilla.org/messenger/msgwindow;1"].createInstance(Components.interfaces.nsIMsgWindow);
msgComposeService.OpenComposeWindow(null,null,uri,Components.interfaces.nsIMsgCompType.Draft,Components.interfaces.nsIMsgCompFormat.Default,identity,msgWindow);
I would suggest injecting the eml file into a local Drafts folder so as to get an nsIMsgDBHdr, and then calling the ComposeMessage function with Ci.nsIMsgCompType.Draft, Ci.nsIMsgCompFormat.Default, yourMsgHdr.folder, yourMsgHdr'sURI.
I think there are several StackOverflow answers on how to inject a given message into a folder.