Click to See Complete Forum and Search --> : saving a file with ActiveX


Sup3rkirby
05-07-2006, 10:53 AM
Hey, i'm sorry if this is a double post or anything, but i couldn't find anything on this in a search so i decided to post.


I had a script to save a file using the common dialog activex control, but it no longer works for me, so i have been trying to find some source code or samples for it and i have come up empty handed.

Does anyone have some quality, working script to save a file in javascript.


on a little side note, my code below gives me an error at the 'cDialog.ShowSave();'. I have the code below that in the body of my webpage.


function SaveJADEScript()
{
try
{
var GetScript;
GetScript = ReturnScript().replace(/&lt;/g,'<');
GetScript = GetScript.replace(/&gt;/g,'>');
var tSaveData;
tSaveData = '<HTML><Head><Title>' + UserCaption + ' - Powered by: Visual JADE Script</Title></Head><Body>' + GetScript + '</Body></HTML>';

cDialog.Filter = "HTML Documents (*.html)|*.html|HTM Documents (*.htm)|*.htm)|Text Documents (*.txt)|*.txt|All Files (*.*)|*.*";
cDialog.ShowSave();
if(cDialog.filename > "")
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var tDocument = fso.CreateTextFile(cDialog.filename, true);
tDocument.write(tSaveData);
tDocument.Close();
alert("'" + cDialog.filename + "' was saved!");
cDialog.filename = "";
} else {
return;
}
}
catch(e)
{
var sCancel = "true";
alert("The following error has occured:\n\n" + e);
}
}


<OBJECT CLASSID="clsid:5220cb21-c88d-11cf-b347-00aa00a28331">
<PARAM NAME="LPKPath" VALUE="comdlg.lpk">
</OBJECT>

<OBJECT ID="CommonDialog1" WIDTH=32 HEIGHT=32
CLASSID="CLSID:F9043C85-F6F2-101A-A3C9-08002B2F49FB"
CODEBASE="http://activex.microsoft.com/controls/vb5/comdlg32.cab">
</OBJECT>

phpnovice
05-07-2006, 04:48 PM
Saving a file is very easy to do (very!), and cross-browser, too, if you use server-side code to do so.

Sup3rkirby
05-07-2006, 06:40 PM
yes, but here, i am doing it client-side. I guess i wouldn't mind a server-side way to save data(simple be able to allow user to pick filename and then save a var(that js will define) as that filename) if you are offering. But my problem is with the script.

felgall
05-07-2006, 07:09 PM
Javascript has no file access whatsoever. JScript (the Internet Explorer equivalent) can only access files via ActiveX and the particular controls that it uses are normally disabled for intranet use and can only be used on an intranet. The code you have may work on an intranet but certainly will never work anywhere else no matter how you modify it as there is no client side way to save anything on the internet (apart from the browser save options controlled by the browser and not by the web page).

Sup3rkirby
05-08-2006, 03:42 PM
Ok, it really is simple. I want to know what is wrong with my code as in, why doesn't it work.

This code has worked on the internet and not just on an intranet. I have used Javascript(client-side script) to save a file on the user's computer(with their permission of course). Which is what the script did, until recently. It brought up a save file dialog and allowed the user to specify a file and location on their computer, then the script would save the file, based on the vars in my script. IE(i don't know about other browsers) would give a message about allowing the activex control to run and norton or mcaffe would also give a warning about the script(since it is trying to save a file on the computer).

But the point is that it did work and no longer does. I was unable to find any information about using the common dialog control in javascript so i asked here how i could fix my problem, or at least where i can find some help on using this activex in js.