473,224 Members | 1,559 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

File Directory Dialog Box

Is there a way in Javascript to bring up dialog boxes for both opening and
then also saving a file?

Jul 23 '05 #1
12 35533
In article
<96******************************@localhost.talkab outprogramming.com>,
rp*****@nospam.indy.rr.com enlightened us with...
Is there a way in Javascript to bring up dialog boxes for both opening and
then also saving a file?


Please clarify the question.
What file is being opened?
What do you mean by 'dialog box'? A prompt? A window? A "browse" button? A
modal dialog window?

What do you mean by "and then also"? Same button/prompt/whatever does both
tasks? A dialog box for both tasks, but the dialog box is not the same
object?
--
--
~kaeli~
Is it true that cannibals don't eat clowns because they
taste funny?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2
This is going to be a file compare program. I just need to have the
standard windows open file dialog box open so the user can select the
file, i will use this twice so they can choose the two file's to be
compared. After the compare i want the standard windows save as box to
appear so they can save the results file.

Jul 23 '05 #3
> I just need to have the
standard windows open file dialog box open so the user can select the
file, I will use this twice so they can choose the two files to be
compared. After the compare I want the standard windows save as box to appear so they can save the results file.


In general, Javascript cannot read or write files from the local
filesystem.

You can create an "open" dialog by creating an <input type="file"> form
element and could probably open it by invoking its onclick method
(though I haven't tried it). But I don't think that the content of the
selected file is available to Javascript (again, I haven't tried).
Similarly a server-side implementation can trigger a "save as" and/or
"open with" dialog by returning content of a type that the browser
cannot handle natively, but I don't believe there is a way for
Javascript to generate such content.

I would be curious to know if anyone can suggest a way of doing this.

--Phil.

Jul 23 '05 #4
I dont plan on having the browser open and doing this in an html page, i
guess i was assuming you could run javascript by itself like vbscript

Jul 23 '05 #5
In article <4d7cc225a92f001ec7ced86507adebc5
@localhost.talkaboutprogramming.com>, rp*****@nospam.indy.rr.com enlightened
us with...
This is going to be a file compare program. I just need to have the
standard windows open file dialog box open so the user can select the
file, i will use this twice so they can choose the two file's to be
compared. After the compare i want the standard windows save as box to
appear so they can save the results file.


The file input type prompts for a file on button click.
<input type="file">

For saving the results, I believe this would work. (Windows / MSIE only?)
document.execCommand('SaveAs');

If this is running on a PC, you may want to look into using an HTA with
Windows Script Host. You don't tend to run into as many security problems
that way. You get more stuff to play with, too. Check out FileSystemObject.

HTH
--
--
~kaeli~
Abdicate (v.), to give up all hope of ever having a flat
stomach.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #6
You can.. as an HTA application.
HTA gets a lot of bad press because it's an obvious tool for virus
writers, but it effectively allows you to write an HTML application
that lives outside the Browser sandbox. If you're not looking to put
it online, and need a rapid dev environment, it's ideal. I've used it
to produce simple applications before that leverage the easy displaying
power of HTML, to be run from a local pc or over a network. Obviously
all your code is visible, so not recommended for anything that requires
security.

Also, because it's out of the sandbox, you can do all manner of loading
and saving files using the standard FileSystemObject (or any other Com
type stuff).

Jul 23 '05 #7
Where can i get information on HTA.

Jul 23 '05 #8
Kind of hard to find definitive guides to all it's uses, but
http://msdn.microsoft.com/workshop/a...taoverview.asp
gives you an overview. Basically it's an HTML file, saved as .HTA, run
using MSHTA.exe (in windows path).
Think it only really needs some sort of rudimentary tag in the head
like
<HTA:APPLICATION ID="oHTA"
APPLICATIONNAME="MyApp"

From there just build HTML as usual. I keep my scripts in a seperate

..js file, linked in.

It's sometimes hard to find Javascript syntax for things like
FileSystemObject, but the info is out there on the web. Takes some time
to find, and if you are familiar with the VB versions, it doesn't
require much altering.

You could of course write the HTA using VBScript...

Jul 23 '05 #9
I have coded the open dialog in vbscript but couldn't find the save as, as
vbscript is the preferred method for the client.

Jul 23 '05 #10
"rockocubs" <rp*****@nospam.indy.rr.com> writes:

(please remember to include *some* context for your posting)
I dont plan on having the browser open and doing this in an html page, i
guess i was assuming you could run javascript by itself like vbscript


You can. On Windows-boxes, you can use any language supported by the
Windows Scripting Host. E.g., make a file called "test.js" containing:

alert("this works!");

and run it with "wscript test.js".

However, Javascript itself has no method of working with files, or any
other I/O for that matter. All of that is provided by the environment
the script is run in. The environment in browsers is the one assumed
by people in this group unless something else is stated.

If you run your scripts using "wscript", you should consult the
documentation for the Windows Scripting Host to find out what features
are available.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #11
"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:wt**********@hotpop.com...
"rockocubs" <rp*****@nospam.indy.rr.com> writes:

(please remember to include *some* context for your posting)
I dont plan on having the browser open and doing this in an html
page, i
guess i was assuming you could run javascript by itself like vbscript
You can. On Windows-boxes, you can use any language supported by the
Windows Scripting Host. E.g., make a file called "test.js" containing:

alert("this works!");

and run it with "wscript test.js".


And get the error:
Script: \path\test.js
Line: 1
Char: 1
Error: Object expected
Code: 800A138F
Source: Microsoft JScript runtime error
However, Javascript itself has no method of working with files, or any
other I/O for that matter. All of that is provided by the environment
the script is run in. The environment in browsers is the one assumed
by people in this group unless something else is stated.
The error encountered above is precisely because of this fact. alert()
is a method provided by the default global object to scripts executing
in Internet Explorer. alert() is not a method available to scripts
running in wscript/cscript because the host does not expose/provide such
a method.

To popup a dialog in wscript, you'd use:

WScript.Echo("this works!");

(note this echos to the console when the script is executed with cscript
test.js).

To have a version that does the equivlent of alert() for both wscript
and cscript, you'd use:

var wshShell = new ActiveXObject('WScript.Shell');
wshShell.Popup("this works!");
If you run your scripts using "wscript", you should consult the
documentation for the Windows Scripting Host to find out what features
are available.


Indeed.

For relatively clean list of available WSH objects, properties and
methods, I prefer <url:
http://www.devguru.com/Technologies/...h_objects.html />

All the objects available there are instatiated (with the exception of
TextStream, which is returned by the StdErr, StdIn and StdOut properties
of the WScript object) in JScript using:

var wshWhatever = new ActiveXObject('WScript.Whatever');

There are also all sorts of other ActiveXObjects which are available
from WSH, such as the FileSystemObject <url:
http://msdn.microsoft.com/library/en...FileSystem.asp
/>

Note that these references are in no way intended to be a complete list
of references, only a sample of the types of references available on the
Web. Other references can be obtained by using Google to search for
something like:

"<object you are interested in> activexobject site:microsoft.com"

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #12


*** Sent via Developersdex http://www.developersdex.com ***
Jul 23 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Martin | last post by:
Again drawing on the groups experience:- 1. For general file opening and file saving, using VB6, are there any issues with using the FileOpen and FileSave Common Dialog Boxes? 2. Is using the...
3
by: bbxrider | last post by:
running win2k adv server/ iis5.0 trying to setup on my web page where browsers can download a file, an .xls so been trying to figure out with a download 'link' what invokes the standard ms file...
5
by: David Webb | last post by:
The problem started when the Working Folder for a project was somehow set to the folder of another project. I set the correct working folder in VSS and deleted the .vbproj files that had been...
2
by: yanivoliver | last post by:
Hey, I'm currently trying to find a way to open a dialog box that will allow me to select more than one file at a time, so if I want to upload select all the files in a directory, I won't have...
0
by: thomasp | last post by:
Wrong title should be File Save Dialog. I have a VB2005 program that has to import data from a 3.5 floppy drive and USB drives. I use a file open dialog to choose the file, works great. The...
5
by: Neil Rossi | last post by:
I have an issue with a particular ASP page on two web servers. Let's call these servers Dev1 and Beta1. Both Servers are running IIS 5, Windows 2000 SP4 with "almost" all of the latest patches. ...
3
by: Highlander | last post by:
Hello all. Consider the following HTA: <HTML> <HEAD> <TITLE></TITLE></HEAD> <BODY> <SCRIPT LANGUAGE="VBScript"> Sub ButBrowse_onclick() '-- show browse window and Get file path:
11
by: GaryDean | last post by:
We created a "File" website on XP and transferred it over to server2003. Now we want to change it to an HTTP site. Without creating a new project and importing everthing, it there a way to convert...
3
by: ArmageddonAsh | last post by:
I'm trying to make an application that will allow the user to enter data into a flexgrid (that's done) and then save the data from that flexgrid into a CSV file but even though the file is made none...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.