Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hai,

OpenFileDialog is not working in windows form. Its strucking (its not opening) the winform when I use openfiledialog control.

I think i missed some properties.Plese help me.


And one more this is not working inside installer setup only. The same win form will be work perfectly alone without setup installer.


Thanks
Posted
Comments
Mehdi Gholam 26-Nov-11 6:55am    
Show your code.
Member 7684075 26-Nov-11 7:03am    
Hi Mehdi Gholam,

This is only my code.

This is working fine without setup. This winform i am calling inside web setup project during installation. that time only not working.
if (result == DialogResult.OK) // Test result.
{
txtUploadFile.Text = this.fdDestPath.FileName;
}
Member 7684075 26-Nov-11 7:09am    
sorry i missed one line code for creating an instance for DialogResult DialogResult result = fdDestPath.ShowDialog();

my full code is

DialogResult result = fdDestPath.ShowDialog();

if (result == DialogResult.OK) // Test result.
{
txtUploadFile.Text = this.fdDestPath.FileName;
}
Mehdi Gholam 26-Nov-11 7:23am    
Looks ok.
Member 10059571 22-Dec-15 4:16am    
it is fake becuase dialog result is a property of window that get and set value with showdialog.

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog im = new OpenFileDialog();
            im.Title = "to select image";
            im.InitialDirectory = @"f:\";
            im.Filter = "All files(*.*)|*.*|All files(*.*)|*.*";
            im.FilterIndex = 100;
            im.RestoreDirectory = true;
            if (im.ShowDialog() == DialogResult.OK)
            {
                txtUploadFile.Text = im.FileName;
            }
        }
    }
}
 
Share this answer
 
v2
Comments
Member 7684075 26-Nov-11 7:22am    
Hi Kalaiking, I accept you. If i execute the form separately (I mean not combine with installer) its working fine . At the same time same form I included with web setup project (installer). So when this win form works with setup openfiledialog and folderopendialog is not working. So please help me how to solve this issue?
kalaiking 26-Nov-11 7:26am    
simple mistake can stop application.. check your code from namespace , if you have time ...
kalaiking 26-Nov-11 7:28am    
i hope in your project has this function already..
check all links or forms..
The problem is that the MSI thread is running as an MTA thread, but the FileDialog.ShowDialog requires an STA thread.  To achieve this you will need to start a STA background thread and call the dialog from that thread. Basically I did the following:

-          Added the DialogState class.  This keeps track of the input and output for the thread.

-          Added the STAShowDialog function.  This function takes a FileDialog, calls ShowDialog on a background STA thread, and then returns the results.

-          Changed the call from DialogResult ret = frm.ShowDialog(); to DialogResult ret = STAShowDialog(frm);


Check this post for a complete information http://blogs.msdn.com/b/smondal/archive/2012/12/31/10059279.aspx[^].



[edit]Code lang changed[/edit]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900