I created a variable to hold a relative path because I cannot have a direct path since this will be installed on different PCs.
var mainUrlCONST = "../../annotations/annotate.xml";
When the initial page of the program loads, it checks to see if the file exists.
If it does not, it creates it.
Now here-in lies the problem, it reads from exactly where I want it to, but if it does not
see the file there, it creates it somewhere else on the PC instead of the location I specified.
This checks for the file:
function initializeAnnotationFile()
{
try
{
var connection = new ActiveXObject("Microsoft.XMLHTTP");
connection.open("GET", mainUrlCONST, false);
connection.send();
if ( connection.readyState == 4 )
{
response = connection.responseText;
}
xml = response;
mainExists = true;
}
catch(e)
{
mainExists = false;
}
}
This creates the file if it does not exist:
function createAnnotationFile()
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.CreateTextFile(mainUrlCONST, true);
s.WriteLine( "<list>" );
s.WriteLine( " <section title='Annotations'>" );
s.WriteLine( " </section>" );
s.WriteLine( "</list>" );
}
Here is the direct path that works, if it will help any.
var mainUrlCONST = "G:/folder/annotations/annotate.xml";
There has been problems with
FSOand relative paths. All documentation says, that paths can be either absolute or relative, but personally I never have got relative paths to work.I’m using an installation folder -based addressing system in my local apps. A simplified version is something like this:
*= IE returns /G:/… when HTA returns G:/…defRootnow contains an absolute path to the installation folder, no matter where it is saved.Put this code to a JS-file in the installation folder of your application. Where ever you need a path, provide it based on
defRooti.e. counted from the installation folder. In your case (assumingfolderis the installation folder) you can use it like this:I’ve used this technique for portable apps, and it works like a charm. You can make executable copies to memory sticks, CDs, DVDs, where ever you want, without need to touch the code at all.