473,406 Members | 2,549 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,406 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 35556
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.