tags:

views:

286

answers:

1

I am trying to add video files to a sql server database table and one of my field is supposed to be the length of the video file. Is there an easy way to get that information in asp.net for files of type .flv - avi - mpg ...?

update: i should have precised it .. i meant length in terms of minutes and seconds.

+2  A: 

I assume that you want to store a BLOB in the SQL Server database table and the length you are referring to is the length of the BLOB. Use the FileInfo class as in the following example.

using System.IO; 
FileInfo fi = new FileInfo(somepath);
int len = fi.Length;

If you are instead referring to the duration (time length) of the video file see here how to do just that.

Microsoft.DirectX.AudioVideoPlayback.Video video = new Microsoft.DirectX.AudioVideoPlayback.Video(path);
StringBuilder sb = new StringBuilder();
sb.Append(video.Caption);
sb.Append("\r\n");
sb.Append(video.Size.Width.ToString());
sb.Append( "\r\n");
sb.Append(video.Size.Height.ToString());
sb.Append("\r\n");
sb.Append(video.Duration.ToString());
textBox1.Text = sb.ToString();
smink