0

I'm trying to write a C# code that handles file uploading automaticly. The follow I need to implement is to choose a file from an open file dialog:

I managed to find the window using users32.dll FindWindow() method. But i have no idea how to set the input if the dialog and approve the chosen file (choose a file & press OK).

My Code so far:

[DllImport("user32.dll")]
public static extern int FindWindow(string lpClassName, string lpWindowName);

public const int WM_SYSCOMMAND = 0x0112;
public const int SC_CLOSE = 0xF060;
public const int WM_SETTEXT = 0x000C;

private void ChooseFile()
{
    // retrieve the handler of the window  
    int iHandle = FindWindow("#32770", "File Upload");
    if (iHandle > 0)
    {
        //Choose File
        //Press OK
    }
}

Any help will be much appreciated.

1
  • Just to clarify my question, I don't need to open a new dialog, just to control a dialog opened by another processes (FireFox file upload dialog). Commented Jan 16, 2013 at 8:56

3 Answers 3

1

You have C# class OpenFileDialog (http://www.dotnetperls.com/openfiledialog), not necessary for user32.dll.

Sign up to request clarification or add additional context in comments.

Comments

1

What you are trying to do do is a bit odd. You are calling Win32 function, but all you need is to use OpenFileDialog class, which is proper .NET way here (MSDN OpenFileDialog)

OpenFileDialog dlg = new OpenFileDialog();
DialogResult res = dlg.ShowDialog();
if (res == DialogResult.OK)
{
    string filePath = dlg.FileName;
    // do your upload logic here
}

1 Comment

Hi Jan. I want to take control of a window opened by another process and not open a new dialog window, can I interact with a Dialog window using OpenFileDialog class?
0

After allot of research i found the solution.

I used Windodows.Form.SendKeys class which simulates the keyboard and send the string to the focused window.

here is the code:

 SendKeys.SendWait(fileInfo.FullName);
 Thread.Sleep(2000);
 SendKeys.SendWait("{ENTER}");
 Thread.Sleep(5000);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.