1

I'm currently developing a C# WinForms application in VS2012 (.NET 4.0). The application is a bit like an Email client and displays a list of messages. And each message can have one or one files attached. The file attachments are stored on a different server, which can only be accessed using another user account (and not by the logged on user).

When the user double clicks on a File Attachment I need to open the file and display it in the associated application. i.e. TXT files in Notepad, DOCX files in Word, etc.

I was hoping I could just pass the full file name into the System.Diagnostics.Process.Start method, with the correct username, password and domain values and it would open the file in the associated application. e.g.

SecureString password = new SecureString();
"MyPassword".ToCharArray().ToList().ForEach(password.AppendChar);

System.Diagnostics.Process.Start(@"\\MyServer\MyFolder\MySubFolder\MyFile.docx",
                                 "MyUsername",
                                 password,
                                 "MyDomain");

But an exception is thrown with the message: The specified executable is not a valid application for this OS platform.

I've also tried creating a ProcessStartInfo object instance and setting the FileName property to "Explorer.exe" and the Arguments property to @"\\MyServer\MyFolder\MySubFolder\MyFile.docx", and passing it as the parameter into the System.Diagnostics.Process.Start method. But this doesn't work either. No exception is thrown and the file isn't displayed either.

But if you look at the object returned by the System.Diagnostics.Process.Start method you see that an InvalidOperationException has occurred.

My C# question is, how can I open and display a file (in it's associated application), when the file is stored on a server that can only be accessed using different user credentials?

m_collard
  • 2,008
  • 4
  • 29
  • 51

1 Answers1

0

I think this should work

Step 1. Find the App registered with the extension Step 2. Use the same Api that was mentioned System.Diagnostics.Process.Start("App from the current Machine that was found in step 1", @"\MyServer\MyFolder\MySubFolder\MyFile.docx", "MyUsername", password, "MyDomain");

See the following links of how to find the register app for an extension

How to get recommended programs associated with file extension in C#

http://www.codeproject.com/Articles/17023/System-File-Association

Community
  • 1
  • 1
unniks
  • 166
  • 7