hi all, how can i start any application from c sharp
i mean for example, if i have an openfiledialog and the user opened it and selected any file and opened it, i need this file to opened in its application whatever its extension and its default start application.
i have googled and found that Process.Start takes the file name and its application but i don't know what is the type of the file the user is going o open
thanks in advance for any replies.

Process.start() will run an application. But if you pass to it a document. like a .jpg it will open in whatever its default application is. for example passing "http://www.dianiweb.com" would open your default web browser and navigate it to daniweb.

if you want to control the application that opens said doument, you can create a process object, and set its startinfo property to the document, and pass the program to run it in into its start method.

System.Diagnostics.Process.Start() will open anything(thats valid), in its default application.

but if u want to know the type of the file, u will have to get the extention of the file -- System.IO.Path.GetExtension(string Path)

.doc = document
.mp3 = ....
well u can figure out what im sayin

hi all, how can i start any application from c sharp
i mean for example, if i have an openfiledialog and the user opened it and selected any file and opened it, i need this file to opened in its application whatever its extension and its default start application.
i have googled and found that Process.Start takes the file name and its application but i don't know what is the type of the file the user is going o open
thanks in advance for any replies.

hi...
first of all in proces.start method you need to pass two parameter
like you want to open IE then
process.start("iexplorer.exe","www.google.com");
it will run internet explorer and default page is google...

now according to your requirement you need to set filters for you application....
like which kind of files you want user to play....
like if jpg,jpeg,png,bmp...etc then windowfax viewer....
if .wmv,mpg,mpeg,flv,3gp..etc then for instace vlc...

using flter you get the extension of file selected...and using if condition you can play that.....
ex.. if(path.getExtension(openfiledialog1.filename)==".mpg")
process.start("vlc.exe",openfiledialog1.filename);

then problem solved

Thanks alot fro reply
i tried System.Diagnostics.Process.Start(fileName); and it worked perfect

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.