how to download video file in asp.net with example
hi,i want to download video files using asp.net with c# .give me example with code
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Lalit MPosted Jul 23, 2010, 6:21 AM
public static void GetMovie(string FileLocation, string Url)
{
try
{
string Content = FileManager.GetFileContents(new Uri(Url));
Regex TempRegex = new Regex("var swfArgs = {(.*)}");
Match Match = TempRegex.Match(Content);
Content = Match.Value;
TempRegex = new Regex("\"video_id\": \"(.*?\")");
string VideoLocation = "http://www.youtube.com/get_video?video_id=";
Match = TempRegex.Match(Content);
VideoLocation += Match.Groups[1].Value.Replace("\"", "");
VideoLocation += "&l=";
TempRegex = new Regex("\"length_seconds\": \"(.*?\")");
Match = TempRegex.Match(Content);
VideoLocation += Match.Groups[1].Value.Replace("\"", "");
VideoLocation += "&t=";
TempRegex = new Regex("\"t\": \"(.*?\")");
Match = TempRegex.Match(Content);
VideoLocation += Match.Groups[1].Value.Replace("\"", "");
Stream TempStream;
FileManager.GetFileContents(new Uri(VideoLocation), out TempStream);
BinaryReader TempReader = new BinaryReader(TempStream);
List<byte> Bytes = new List<byte>();
while (true)
{
byte[] Buffer = new byte[1024];
int Length = TempReader.Read(Buffer, 0, 1024);
for (int x = 0; x < Length; ++x)
{
Bytes.Add(Buffer[x]);
}
if (Length == 0)
break;
}
FileManager.SaveFile(Bytes.ToArray(), FileLocation);
}
catch { }
}