Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003
This is the forum to discuss the Wrox book Professional VB.NET 2003 by Bill Evjen, Billy Hollis, Rockford Lhotka, Tim McCarthy, Jonathan Pinnock, Rama Ramachandran, Bill Sheldon; ISBN: 9780764559921
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 5th, 2006, 06:57 AM
Authorized User
 
Join Date: Apr 2004
Location: glasgow, , United Kingdom.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using the OpenFileDialog

Why do I keep getting "It is invalid to show a modal dialog or form when the application is not running in UserInteractive mode...."
when I try to use a common dialog on my web application and how do I fix this?
  #2 (permalink)  
Old May 14th, 2006, 02:15 PM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Location: Fuquay Varina, NC, USA.
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

You cannot create and show an Open File dialog from your web application. Remember that a web application has no state; the request is sent from the client browser to the web server. The web server builds the web page and sends it to the client browser and the request is complete and there is no connection between the client and server.

Why are you trying to display a Open File dialog in your web form? There may be viable alternatives to what you are trying to accomplish.

Thearon
  #3 (permalink)  
Old May 17th, 2006, 07:38 PM
Registered User
 
Join Date: May 2006
Location: San Rafael, CA, .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I, too, have been looking at trying to provide a way for users to see folders/files on the server. Maybe the answer is to simply permit them the use of FTP?

  #4 (permalink)  
Old May 17th, 2006, 07:40 PM
Registered User
 
Join Date: May 2006
Location: San Rafael, CA, .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I too was looking at providing a dialog for opening folders on the server.
Perhaps the answer is found in using FTP?
  #5 (permalink)  
Old May 20th, 2006, 05:57 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Location: Fuquay Varina, NC, USA.
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

If you want users to download files, then perhaps you should use server side code to build a web page that displays the file names with links to the files. This would probably be the best way to do this.

Thearon
  #6 (permalink)  
Old May 29th, 2006, 11:42 PM
Registered User
 
Join Date: May 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I had the same problem, to get around it you have to thread the OpenFileDialog:

Here is the thread instance
-----------
OpenFileDialog_Class oOpenDialog = new OpenFileDialog_Class();
Thread tFileNameThread = new Thread(new ThreadStart(oOpenDialog.StartThread));
tFileNameThread.SetApartmentState(ApartmentState.S TA); //This must be set
tFileNameThread.Start(); //Start the thread
tFileNameThread.Join();
sTemplate = oInvoice.GetTemplateName(); //Get the path/name of the file to use
---------------
Below is the class for the thread above

using System;
using System.IO;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Windows.Forms;

/// <summary>
/// Summary description for OpenFileDialog_Class
/// </summary>
public class OpenFileDialog_Class
{
    public string sTemplate = null;
    public OpenFileDialog_Class()
    {
        //
        // TODO: Add constructor logic here
        //
        //GetTemplate();
    }
    public void StartThread()
    {
        sTemplate = GetTemplate();
    }

    [STAThread] //Must have this declared, or your thread crashes
    public string GetTemplate()
    {
        string sTemplate = null;
        try
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
            openFileDialog.Filter = "Word Template (*.dot)|*.dot|All files (*.*)|*.*";
            openFileDialog.FilterIndex = 1;
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                int iStartFile = openFileDialog.FileName.LastIndexOf("\\");
                try
                {
                    sTemplate = openFileDialog.FileName;
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine(ex.Message);
                }
            }
        }
        catch (Exception ex)
        {
            //LogWriter_Class sw = new LogWriter_Class();
            //sw.logError(ex, " error, check the log file.", " Error");
        }
        return sTemplate;
    }
    [STAThread]
    public string GetTemplateName()
    {
        return sTemplate;
    }
}

This works ok, only problem is the OpenFileDialog is not in Focus, your IE is, but you can Alt+Tab it easy enough.

My use is to select a Word Template document to create an Invoice for my sales.

Hope this helps.
Scott Thornton
www.thornton-imports.com


  #7 (permalink)  
Old December 6th, 2006, 02:24 AM
Authorized User
 
Join Date: Aug 2005
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Byock
Default

Cannot use these

using System.Windows.Forms;
using System.Web.UI.WebControls.WebParts;

In web forms

any other work around, so we can have OpenFileDialog or SaveFileDialog in a webform?


Quote:
quote:Originally posted by scott__thornton
 I had the same problem, to get around it you have to thread the OpenFileDialog:

Here is the thread instance
-----------
OpenFileDialog_Class oOpenDialog = new OpenFileDialog_Class();
Thread tFileNameThread = new Thread(new ThreadStart(oOpenDialog.StartThread));
tFileNameThread.SetApartmentState(ApartmentState.S TA); //This must be set
tFileNameThread.Start(); //Start the thread
tFileNameThread.Join();
sTemplate = oInvoice.GetTemplateName(); //Get the path/name of the file to use
---------------
Below is the class for the thread above

using System;
using System.IO;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Windows.Forms;

/// <summary>
/// Summary description for OpenFileDialog_Class
/// </summary>
public class OpenFileDialog_Class
{
    public string sTemplate = null;
    public OpenFileDialog_Class()
    {
        //
        // TODO: Add constructor logic here
        //
        //GetTemplate();
    }
    public void StartThread()
    {
        sTemplate = GetTemplate();
    }

    [STAThread] //Must have this declared, or your thread crashes
    public string GetTemplate()
    {
        string sTemplate = null;
        try
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
            openFileDialog.Filter = "Word Template (*.dot)|*.dot|All files (*.*)|*.*";
            openFileDialog.FilterIndex = 1;
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                int iStartFile = openFileDialog.FileName.LastIndexOf("\\");
                try
                {
                    sTemplate = openFileDialog.FileName;
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine(ex.Message);
                }
            }
        }
        catch (Exception ex)
        {
            //LogWriter_Class sw = new LogWriter_Class();
            //sw.logError(ex, " error, check the log file.", " Error");
        }
        return sTemplate;
    }
    [STAThread]
    public string GetTemplateName()
    {
        return sTemplate;
    }
}

This works ok, only problem is the OpenFileDialog is not in Focus, your IE is, but you can Alt+Tab it easy enough.

My use is to select a Word Template document to create an Invoice for my sales.

Hope this helps.
Scott Thornton
www.thornton-imports.com


  #8 (permalink)  
Old May 28th, 2007, 02:57 AM
Registered User
 
Join Date: May 2007
Location: BenTre, goods, Vietnam.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to huynhvanvu03hcb
Default

Quote:
quote:Originally posted by Byock
 Cannot use these

using System.Windows.Forms;
using System.Web.UI.WebControls.WebParts;

In web forms

any other work around, so we can have OpenFileDialog or SaveFileDialog in a webform?


Quote:
quote:Originally posted by scott__thornton
 I had the same problem, to get around it you have to thread the OpenFileDialog:

Here is the thread instance
-----------
OpenFileDialog_Class oOpenDialog = new OpenFileDialog_Class();
Thread tFileNameThread = new Thread(new ThreadStart(oOpenDialog.StartThread));
tFileNameThread.SetApartmentState(ApartmentState.S TA); //This must be set
tFileNameThread.Start(); //Start the thread
tFileNameThread.Join();??
sTemplate = oInvoice.GetTemplateName(); //Get the path/name of the file to use
---------------
Below is the class for the thread above

using System;
using System.IO;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Windows.Forms;

/// <summary>
/// Summary description for OpenFileDialog_Class
/// </summary>
public class OpenFileDialog_Class
{
    public string sTemplate = null;
    public OpenFileDialog_Class()
    {
        //
        // TODO: Add constructor logic here
        //
        //GetTemplate();
    }
    public void StartThread()
    {
        sTemplate = GetTemplate();
    }

    [STAThread] //Must have this declared, or your thread crashes
    public string GetTemplate()
    {
        string sTemplate = null;
        try
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
            openFileDialog.Filter = "Word Template (*.dot)|*.dot|All files (*.*)|*.*";
            openFileDialog.FilterIndex = 1;
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                int iStartFile = openFileDialog.FileName.LastIndexOf("\\");
                try
                {
                    sTemplate = openFileDialog.FileName;
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine(ex.Message);
                }
            }
        }
        catch (Exception ex)
        {
            //LogWriter_Class sw = new LogWriter_Class();
            //sw.logError(ex, " error, check the log file.", " Error");
        }
        return sTemplate;
    }
    [STAThread]
    public string GetTemplateName()
    {
        return sTemplate;
    }
}

This works ok, only problem is the OpenFileDialog is not in Focus, your IE is, but you can Alt+Tab it easy enough.

My use is to select a Word Template document to create an Invoice for my sales.

Hope this helps.
Scott Thornton
www.thornton-imports.com


no


Similar Threads
Thread Thread Starter Forum Replies Last Post
OpenFileDialog on .NET Compact Framework yukijocelyn C# 2005 0 July 4th, 2008 11:35 PM
Drag/Drop from OpenFileDialog using C# Windows App MukeshAgarwal C# 1 July 10th, 2007 10:44 AM
OpenFileDialog using vba Suomi Access VBA 9 June 13th, 2007 01:07 PM
OpenfileDialog class krellee General .NET 1 September 14th, 2005 01:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.