all groups > dotnet windows forms > may 2007 >
You're in the

dotnet windows forms

group:

Call system application to open a specified file.



RE: Call system application to open a specified file. VR Ravinuthala
5/31/2007 10:07:00 AM
dotnet windows forms: you can do it couple of ways.

First using File select dialog, select the name of the file selected into a
string.

1. use pinvoke and call the api shellexecute with the bmp file selected.
here is the unmanaged example.
http://support.microsoft.com/default.aspx/kb/170918

2. launch mspaint.exe with process class in .NET
System.Diagnostics.Process proc = new System.Diagnostics.Process();

proc.StartInfo.FileName = "mspaint.exe";
// set windows dir
proc.StartInfo.WorkingDirectory = .....
// pass the bmp file name with full path
proc.StartInfo.Arguments =

proc.Start();

-VR

[quoted text, click to view]
Call system application to open a specified file. zlf
5/31/2007 11:31:36 PM
Hi,
In my program, client is allowed to select a image file from open file
dialog. And I am required to provide a preview button, when clicking it,
system program like paint should be called to open that file.

May you tell me how to implement that. Thx

zlf

Re: Call system application to open a specified file. Jeff Gaines
6/2/2007 9:16:39 AM
[quoted text, click to view]

If you call Process.Start using just a document name the default
application (assuming there is one) will open. I use:

public static bool StartProcess(string strCommand, string strWD, out
string strErr)
{
bool blnOK = false;
ProcessStartInfo psi = new ProcessStartInfo();
strErr = "";

// Initialize the ProcessStartInfo structure
psi.FileName = strCommand;
psi.WorkingDirectory = strWD;

psi.RedirectStandardInput = false;
psi.RedirectStandardOutput = false;
psi.UseShellExecute = true;
Process proc = new Process();
try
{
Process.Start(psi);
blnOK = true;
}
catch (Exception e)
{
strErr = e.Message;
blnOK = false;
}
return blnOK;
}

--
Re: Call system application to open a specified file. zlf
6/2/2007 11:19:05 PM
Thank you, I still want to know whether this is way to call the default
assoicated program to open it.
E.g: If bmp is selected, maybe mspaint will be called. If .doc is selected,
microsoft word will be launched. Thx

"VR Ravinuthala" <VRRavinuthala@discussions.microsoft.com> дÈëÏûÏ¢ÐÂÎÅ:B45844D2-C7A7-4786-9DC7-A2813FD3EBA1@microsoft.com...
[quoted text, click to view]

Re: Call system application to open a specified file. zlf
6/3/2007 12:28:37 AM
It works! Thank you :)

"Jeff Gaines" <whitedragon@newsgroups.nospam>
??????:xn0f6zc437m9gp3005@msnews.microsoft.com...
[quoted text, click to view]

AddThis Social Bookmark Button