Windows Scripting
  Home arrow Windows Scripting arrow Page 3 - User Interaction with Common Dialogs in WS...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

User Interaction with Common Dialogs in WSH
By: Nilpo/Developer Shed Staff Writer
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2007-04-24

    Table of Contents:
  • User Interaction with Common Dialogs in WSH
  • Accessing the Common Dialog control directly
  • Accessing dialogs through other applications
  • Watch it in action

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    User Interaction with Common Dialogs in WSH - Accessing dialogs through other applications


    (Page 3 of 4 )

    If you can't call the Common Dialog control directly, it makes sense to try and call it from an application that can.  However, this seems like a bit of a stretch.  The Common Dialog control would be called within the code of the application so we would need to find a way to trap the results it returns.

    To do that, we'll look to Internet Explorer.  If you create a web page with a Browse form button, clicking the button will launch the File Open dialog box.  The results of that dialog are then returned to the button's accompanying text box.

    Set objIE = CreateObject("InternetExplorer.Application")

    objIE.Navigate("about:blank")

    Do Until objIE.ReadyState = 4

       WScript.Sleep 1

    Loop

    objIE.Document.Write("<html><body><input id=field " _

       & "type=file></body></html>")

    objIE.Document.all.field.focus

    objIE.Document.all.field.click

    WScript.Echo objIE.Document.all.field.value

    objIE.Quit

    This example goes a little further than the VBS scripting you're probably used to because we're also implementing some browser scripting as well.

    Browser scripting relies on the Document Object Model (DOM) for controlling web page elements.  In this case, we're using client-side scripting to control a web form.  The web page itself was also created with the DOM.

    We begin by loading a blank HTML page in Internet Explorer using the IE object's Navigate method.  Then we write an HTML string to the page using the Write method of DOM's Document object.

    We make sure that the form field is in focus and then simulate a mouse click on the Browse button.  This brings up the Open file dialog box.  Once the user makes a selection, the value is returned to the form field.

    We finish up by reading the field's contents with the Value property.  Make sure to use IE's Quit method to close the application when you're finished.  Otherwise, the process will remain running in the background.

    So why don't I like this method?  Well, first off it does not give you any control over the dialog box's appearance or functionality.  It's very cut-and-dry.  Second, I don't like the idea of having to launch another application if I can help it.

    This does work as a viable alternative to the Common Dialogs control, however, because it's a pretty safe bet that IE will be installed on every machine.

    The final reason I don't like this approach is because you only have access to a File Open dialog.  What if I want to save a file?  Technically, I could still use this since we're only returning a string but that could be confusing to our users.

    More Windows Scripting Articles
    More By Nilpo/Developer Shed Staff Writer


       · Hey, guys. Thanks for joining me again. In this article how show you how to give...
       · Hi,I am regular reader of your articles. Its very informative. Keep...
       · Thanks for reading.Beginning with the basics, this does require Internet...
     

    WINDOWS SCRIPTING ARTICLES

    - Introducing Two-Way Data Binding using Silve...
    - Silverlight 2.0 Application Development with...
    - Burning Multisession CDs with IMAPI2 in WSH
    - Creating a Silverlight 2.0 Application that ...
    - Burning CDs with the IMAPI2 Control
    - Burning CDs in Windows XP with WSH
    - Advanced Word Object Scripting
    - Reading and Printing Word Documents in WSH
    - Scripting Microsoft Word
    - Using WSH to Catalog MP3 Files
    - Reading MP3 ID3 Tags in WSH
    - A Brief Look at Menus in WPF
    - More Examples of Simplified Image Processing...
    - Completing a WPF To-Do List Application
    - Simplified Image Processing in GDI+





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT