SUMMARY
This article describes how to display the
Open dialog box and the
SaveAs dialog box on a data access page. Because API calls are not available in scripting languages such as VBScript or JavaScript, you can use the Microsoft Common Dialog ActiveX control or write your own custom "wrapper" in Visual Basic around the API.
You may want to use this technique when you want to prompt the user for the file location from a data access page. You may want to do this, for example, when saving the current recordset as XML. Or you may want to do this if the page contains script to open a document in another application.
This article shows you three methods. The first method is for computers that have the design-time license for the Common Dialog ActiveX control. The second method is for computers that have the Common Dialog ActiveX control but no license. The third method is for computers that do not have the Common Dialog ActiveX control installed.
For additional information about how to start another application from a data access page, click the following article number to view the article in the Microsoft Knowledge Base:
234303
ACC2000: How to Start Another Application from a Data Access Page
For additional information about how to use the Common Dialog file Open dialog with Win32 API, click the following article number to view the article in the Microsoft Knowledge Base:
161286
How To Use a Common Dialog File Open Dialog with Win32 API
For additional information about using and distributing the Common Dialog control from a Web page, click the following article number to view the article in the Microsoft Knowledge Base:
168917
How To Set Up Internet Download for Comdlg32.ocx
Note Only developers who have a valid design-time license for the Common Dialog control may distribute the control for use in their applications or on their Web sites.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
back to the top
Method 1: Design-time license
Follow these steps to display the Common Dialog control from a data access page on a client computer that has the design-time license for the control.
- Create a data access page. Open it in Design View.
- On the Insert menu, click ActiveX Control.
- Click to select the Microsoft Common Dialog Control check box, and then click OK.
- Change the Id property for the control to cd1.
- Add two text box and two command button controls to the page.
- Change the Id property for the text box controls to txtOpen and txtSaveAs.
- Change the Id property for the command button controls to cmdOpen and cmdSaveAs.
- On the Tools menu, click Macro, and then click Microsoft Script Editor.
- Click the arrow in the Object box, and then click cmdOpen in the list. Click the arrow in the Event box, and then click onclick in the list.
- Modify the script as follows:
<SCRIPT language=vbscript event=onclick for=cmdOpen>
<!--
' Show the open dialog box.
with cd1
.DialogTitle = "Open dialog box from data access page"
.Filter = "Graphic files (*.jpg;*.gif;*.bmp)|*.jpg;*.gif;*.bmp" & _
"|Text Files (*.txt)|*.txt|All Files(*.*)|*.*"
.ShowOpen
if len(.FileName) then
txtOpen.value = .FileName
end if
end with
-->
</SCRIPT>
- Click the arrow in the Object box, and then click cmdSaveAs in the list. Click the arrow in the Event box, and then click onclick in the list.
- Modify the script as follows:
<SCRIPT language=vbscript event=onclick for=cmdSaveAs>
<!--
' Show the Save As dialog box.
with cd1
.DialogTitle = "Save As dialog box from data access page"
.Filter = "Graphic files (*.jpg;*.gif;*.bmp)|*.jpg;*.gif;*.bmp" & _
"|Text Files (*.txt)|*.txt|All Files(*.*)|*.*"
.ShowSave
if len(.FileName) then
txtSaveAs.value = .FileName
end if
end with
-->
</SCRIPT>
- Save and then close the page.
back to the top
Method 2: No license
Follow these steps to display the Common Dialog ActiveX control from a data access page on a client computer that has the control but does not have a license for the control.
- Follow the steps in Method 1.
- Download the License Package Tool that is named LPKTool.exe to your local hard disk. To do this, type the following URL in your Web browser:
http://www.microsoft.com/downloads/details.aspx?displaylang=en&familyid=d2728e89-575e-42e9-a6ff-07d0021e68cc - Click Download.
- In the File Download dialog box, click Save.
- In the Save As dialog box, change the Save in box to your download files folder or to other location, click Create New Folder, type Lpk, and then press ENTER.
- With the Lpk folder selected, click Open. Click Save to save the Lpk_tool.exe file to your new Lpk folder.
- When the download is complete, click Close to close the Download dialog box.
- Click Start, click Run click Browse, and then locate your Lpk folder.
- Click Lpk_tool.exe, and then click Open.
- Click OK in the Run dialog box.
- Click Yes to agree to the license agreement. Extract the files to your Lpk folder.
Note During the extraction process, the Lpk_tool.exe files are copied to the Lpktool subfolder in your Lpk folder. - Click OK to close the Installation Complete dialog box.
This utility creates the .lpk file. You can reference this file in the page to provide the run-time license for the Common Dialog control to client computers. - Run the License Package Tool. Add the Microsoft Common Dialog control. Then, put the .lpk file that the tool generates in the same folder as the data access page.
- Open the page in Notepad.
- Find the OBJECT tag for cd1. Put the following OBJECT tag immediately in front of it. Make sure to replace "NameOfLPKFile" with the name of your .lpk file:
<OBJECT CLASSID = "clsid:5220cb21-c88d-11cf-b347-00aa00a28331" VIEWASTEXT>
<PARAM NAME="LPKPath" VALUE="NameOfLPKFile.lpk">
</OBJECT>
- Save and then close the page.
back to the top
Method 3: No control
Follow these steps to display the Common Dialog control from a data access page on a client computer that does not have the control installed.
- Follow the steps in Method 2.
- Open the page in Notepad.
- Find the OBJECT tag for cd1. Put the CODEBASE attribute in front of the closing of the opening OBJECT tag. The OBJECT tags looks as follows:
<OBJECT CLASSID = "clsid:5220cb21-c88d-11cf-b347-00aa00a28331" VIEWASTEXT>
<PARAM NAME="LPKPath" VALUE="NameOfLPKFile.lpk">
</OBJECT>
<OBJECT id=cd1 title="" style="Z-INDEX: 1" tabIndex=1
classid=CLSID:F9043C85-F6F2-101A-A3C9-08002B2F49FB VIEWASTEXT
CODEBASE="http://activex.microsoft.com/controls/vb6/comdlg32.cab">
<PARAM NAME="_ExtentX" VALUE="847">
<PARAM NAME="_ExtentY" VALUE="847">
<PARAM NAME="_Version" VALUE="393216">
<PARAM NAME="CancelError" VALUE="0">
<PARAM NAME="Color" VALUE="0">
<PARAM NAME="Copies" VALUE="1">
<PARAM NAME="DefaultExt" VALUE="">
<PARAM NAME="DialogTitle" VALUE="">
<PARAM NAME="FileName" VALUE="">
<PARAM NAME="Filter" VALUE="">
<PARAM NAME="FilterIndex" VALUE="0">
<PARAM NAME="Flags" VALUE="0">
<PARAM NAME="FontBold" VALUE="0">
<PARAM NAME="FontItalic" VALUE="0">
<PARAM NAME="FontName" VALUE="">
<PARAM NAME="FontSize" VALUE="8">
<PARAM NAME="FontStrikeThru" VALUE="0">
<PARAM NAME="FontUnderLine" VALUE="0">
<PARAM NAME="FromPage" VALUE="0">
<PARAM NAME="HelpCommand" VALUE="0">
<PARAM NAME="HelpContext" VALUE="0">
<PARAM NAME="HelpFile" VALUE="">
<PARAM NAME="HelpKey" VALUE="">
<PARAM NAME="InitDir" VALUE="">
<PARAM NAME="Max" VALUE="0">
<PARAM NAME="Min" VALUE="0">
<PARAM NAME="MaxFileSize" VALUE="260">
<PARAM NAME="PrinterDefault" VALUE="1">
<PARAM NAME="ToPage" VALUE="0">
<PARAM NAME="Orientation" VALUE="1">
</OBJECT>
- Save and then close the page.
back to the top