Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to check uploaded file in fileupload is video file or not using C#.
if any one change the extension of any file in video format like .avi,.mp4 etc that time it must be not upload and throw error...
Posted
Comments
Sergey Alexandrovich Kryukov 28-Jul-14 1:24am    
Why? Do you support all the video files, or just store them? If you cannot play that video file (or whatever you want to do with it), you can consider it as not a video file. Isn't it logical? There are too many different formats, and most of the formats supports different combinations of codecs.
—SA

C#
string fileName = FileUpload1.FileName;
           string FileExtension = fileName.Substring(fileName.LastIndexOf('.') + 1).ToLower();
           if (FileExtension == "flv" || FileExtension == "wmv")
           {



           }
 
Share this answer
 
Comments
krrazyumesh 28-Jul-14 2:31am    
it work but i have one problem if i change the extension of .exe to .avi or any video formate and upload it then it uploaded. but i don't want like this
As Sergey said it is not logical if you want to play it.
Any way you can try with following Java Script function for check formats.

function ValidateVideoupload(Source, flag)
{
var pathTextBox = document.getElementById('txtBoxFilePath');
var FileUploadPath = pathTextBox.value;


var FileExtension = FileUploadPath.substring(FileUploadPath.lastIndexOf('.') + 1).toLowerCase();


if (FileExtension == "AVI"||FileExtension == "MP4"||FileExtension == "DAT"||FileExtension == "MPEG"||FileExtension == "3gp")
{
flag.IsValid = true; // Allow to upload Video File
}
else
{
flag.IsValid = false; // Don't allow to upload Video file
}


}


}
 
Share this answer
 
Comments
krrazyumesh 28-Jul-14 2:31am    
it work but i have one problem if i change the extension of .exe to .avi or any video formate and upload it then it uploaded. but i don't want like this
Gihan Liyanage 28-Jul-14 6:31am    
Can you please Check with C# Mime types and getmimetype() Method.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900