How do I detect the temporary Internet Files location of Internet Explorer through Javascript?
I am attempting to port an Firefox extension to IE. One of the features I need to have is the ability to write to the Temp Files of the browser. In Firefox this was easily done by the following code:
//Create file to store data transferred to desktop app
var file = Components.classes["@mozilla.org/file/directory_service;1"].
getService(Components.interfaces.nsIProperties).
get("TmpD", Components.interfaces.nsIFile);
file.append("MyExtTempFile.txt");
file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666);
// do whatever you need to the created file
This method was preferable rather than hard coding a path in because it could change on different versions of Windows / IE.
I figured out how to create and write to a file in IE by:
var fso = new ActiveXObject("S开发者_如何学JAVAcripting.FileSystemObject");
var fh = fso.CreateTextFile("C:\\Users\\Administrator\\Desktop\\MyExtTempFile.txt", true);
fh.WriteLine("Some text goes here...");
fh.Close();
Now I am just wondering how to automatically detect the temp file location for IE?
fso.GetSpecialFolder(2)
Found here: FileSystemObject.GetSpecialFolder()
FileSystemObject.GetSpecialFolder(2)
will give you temp folder path of OS. It wont give you Temporary internet files' location.
精彩评论