Hi guys, some times you may got a requirement that whether the video url provided by the user is valid or not, you can check it by using the below codes.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
public class UrlValidity
{
public static bool IsValid(string Url)
{
Stream sStream = default(Stream);
HttpWebRequest URLReq = default(HttpWebRequest);
HttpWebResponse URLRes = default(HttpWebResponse);
try {
URLReq = WebRequest.Create(Url);
URLRes = URLReq.GetResponse();
sStream = URLRes.GetResponseStream();
string reader = new StreamReader(sStream).ReadToEnd();
return true;
}
catch (Exception ex)
{
catch (Exception ex)
{
//Url not valid
return false;
}
}
}
No comments:
Post a Comment