Well, you already have the user name and password so you could simply use the Process class to start the process. To get back the file name you can redirect the process output and have the open file dialog application write the file name to the (redirected) console.
For example:
private void button1_Click(object sender, EventArgs e) {
string fileName;
using (var pwd = new System.Security.SecureString()) {
foreach (var ch in password)
pwd.AppendChar(ch);
using (var proc = Process.Start(new ProcessStartInfo {
FileName = "WindowsFormsApplication2.exe",
UserName = userName,
Password = pwd,
UseShellExecute = false,
RedirectStandardOutput = true
})) {
fileName = proc.StandardOutput.ReadLine();
}
}
if (!String.IsNullOrEmpty(fileName))
MessageBox.Show(fileName);
}
And WindowsFormsApplication2.exe is a small WinForms app that simply shows the OpenFileDialog:
static class Program {
[STAThread]
static void Main() {
using (var dlg = new OpenFileDialog()) {
if (dlg.ShowDialog() != DialogResult.OK)
Console.WriteLine();
else
Console.WriteLine(dlg.FileName);
}
}
}
No comments:
Post a Comment