Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / June 2007

Tip: Looking for answers? Try searching our database.

Call system application to open a specified file.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
zlf - 31 May 2007 16:31 GMT
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
VR Ravinuthala - 31 May 2007 18:07 GMT
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

> Hi,
> In my program, client is allowed to select a image file from open file
[quoted text clipped - 4 lines]
>
> zlf
zlf - 02 Jun 2007 16:19 GMT
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...
> you can do it couple of ways.
>
[quoted text clipped - 27 lines]
>>
>> zlf
Jeff Gaines - 02 Jun 2007 17:16 GMT
>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

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;
        }

Signature

Jeff Gaines

zlf - 02 Jun 2007 17:28 GMT
It works! Thank you :)

"Jeff Gaines" <whitedragon@newsgroups.nospam>
??????:xn0f6zc437m9gp3005@msnews.microsoft.com...
> On 02/06/2007 in message <O9SjclSpHHA.1220@TK2MSFTNGP03.phx.gbl> zlf
> wrote:
[quoted text clipped - 34 lines]
> return blnOK;
> }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.