Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determining SaveAs Path

Status
Not open for further replies.

techie99

Programmer
Apr 24, 2003
60
0
0
US
thread216-539453

I'm using the following Javascript command in an HTML page. What it does is bring up the save file dialog box, to which a user uses the drop-down to tell it where to save a file.
document.execCommand('SaveAs'....

What I would like to do is determine what path the user selected. How do I do this? Setting a variable equal to the above only returns a boolean value.

Thanks for all your help...
 
There is no method for retrieving the selected path with execCommand.

You could try instead to use an ActiveX component calling on the BrowseForFolder method which will give you the browse menu and return the selected values.
I have had no luck in using BrowseForFolder with an HTML page though. It works fine with a .hta file which has local resource access but from an HTML page it always reports Access Denied without even giving me an ActiveX warning or option to allow it.

Here is some code you can play around with to test.
Save it with a .hta file extension.
You can try setting it to .htm to see if it runs for you, it will not on my own machine but perhaps the company has altered the security settings of IE.
Code:
<HTML>
<HEAD>
<script type='text/JavaScript'>
function saveFile()
{
  //Call fnfolderDialog to get location to export data to.
  var exportlocation = fnfolderDialog();
  if (exportlocation.substring(0,2) == "::") // Make certain destination is valid (locations like My Computer, Control Panel, My Network, etc.. values begin with ::
  {
    exportlocation = "Cancel";
    alert("Invalid destination selected");
  }
  alert(exportlocation);
}

function fnfolderDialog()
{
  var sCaption = "Select the .exp file for the event you wish to import";
  var sOptions = 0;
  var sInitPath = "C:\\";

  try
  {
    var oShell = new ActiveXObject("Shell.Application");
    var oFolder = oShell.BrowseForFolder(0, sCaption,sOptions,sInitPath);
    var oFolderItem = oFolder.Items().item();
    filepath = oFolderItem.Path;
    filename = oFolderItem.Name;
  }
  catch(e)
  {
    var errtemp = e.description;
    if (errtemp == "'null' is null or not an object")
    {
      errtemp = "";
    }
    if (errtemp == "Invalid procedure call or argument")
    {
      errtemp = "Error: You cannot select a file from a root folder.";
    }
    if (errtemp > "")
    {
      alert(errtemp);
    }
    filepath = "Cancel";
  }
    oFolderItem = null
    oFolder = null
    oShell = null
    return filepath;
}
</script>
</HEAD>
<BODY>
<input type="button" name="btnSaveAs" onclick="saveFile()" value="Save As">
</BODY>
</HTML>

Stamp out, eliminate and abolish redundancy!
 
Thanks for your input, I greatly appreciate it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top