Tuesday, 1 July 2008

Runing Executable Files in ASP .NET

In this post I will provide you with a code snippet that runs an executable file (.exe) on server side.
For this you need to first declare an object of System.Diagnostics.Process type.
Then set few parameters and then start executing!

System.Diagnostics.Process batch =
new System.Diagnostics.Process();
batch.StartInfo.FileName =
batch.StartInfo.Arguments =
String.Format("Arguments go here");
batch.StartInfo.CreateNoWindow = true;
//if you do not want
//to display the window...
batch.StartInfo.WindowStyle =

//now you can start the job...

//if you want to wait until
//the process terminates,
//you can use the following line:

Also note that in order to be able to execute files, you need to have some permissions, here you can find more about security permissions.

You can use this snippet in conjunction with my previous post to build some thing like YouTube ;)

After the user uploads a new video (MPG, AVI and etc.) you can convert the uploaded file to .flv file using this code and FFmpeg tool.

This is a short code for converting videos:

batch.StartInfo.FileName =
batch.StartInfo.Arguments =
String.Format(@"-i ""{0}\t.mpg""
""{0}\t.flv"" -y",

YouTube like FLV Flash Video Player for ASP .NET

You may need to show some videos on your ASP .NET site, right?
You can use YouTube and upload your videos to YouTube and put the link of your uploaded video in your site, it's very easy, but you might not like to have YouTube code in your site...
Here is the solution:
Have your own ASP .NET FLV (Flash Video) Player, sounds great!
The ASPNetFlashVideo Component allows you to add YouTube style Flash Videos (.flv files) to ASP.Net websites. ASPNetFlashVideo requires no Flash programming and is unique.
Flash Video can be encoded easily using free tools provided by Riva and Adobe.
You can also use FFmpeg free tool.
It is a command-line based program, and you can easily use it like:
ffmpege.exe -i test.avi test.flv

You also index your flv files with flvTool2 like this:
flvtool2.exe -U test.flv

It's now done!

All you need to do is to place a ASPNETFlashVideo control on your ASPX pages and set it's 'VideoURL' property to .flv file's path.

This control also supports skinning, full screen playback, does not display "Click to activate and use this control" message and etc.

There is also another YouTube like flash video player available at MyCSharpCorner that automatically converts your uploaded videos to .flv files. But it's source code is not available.