Breaking News

Editors Picks

Tuesday, October 4, 2011

Get IP to Country ,State , city info in asp.net ,C#



First register on this site http://api.ip2locationapi.com/ to get API Key

protected void GetUserLocation()
{
try
{
ipaddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (ipaddress == null)
{
ipaddress = Request.ServerVariables["REMOTE_ADDR"];
}
DataTable dt = UserManage.GetLocationnew(ipaddress);
if (dt.Rows.Count > 0)
{
Location = dt.Rows[0]["countryName"].ToString();
CountryID = Common.GetCountryID(Location);
StateID = Common.GetStateID(dt.Rows[0]["region"].ToString());
}
}
catch (Exception ex)
{
AppBase.handleException("Form:changevote, Function:GetUserLocation", ex);
}

}

public static DataTable GetLocationnew(string ipaddress)
{
DataSet ds = new DataSet();
try
{
DataTable dt = new DataTable();
WebRequest wreq = WebRequest.Create("http://api.ip2locationapi.com/?user= &format=xml&ip=" + ipaddress + "");
WebResponse wres = wreq.GetResponse();
XmlTextReader xmlRead = new XmlTextReader(wres.GetResponseStream());
ds.ReadXml(xmlRead);
}
catch (Exception ex)
{
AppBase.handleException("Form:_Default, Function:GetLocation", ex);
}
return ds.Tables[0];
}


Read more ...

Play video from You tube url in asp.net C#


this code add on aspx page
 
<% GetYouTubeScript(dtPoll.Rows[Count]["PollVideoURL"].ToString());%>
<asp:Literal ID="Literal1" runat="server">asp:Literal>


and this code add on aspx.cs page 
public void GetYouTubeScript(string id)
{
if (id.Contains("="))
{
string[] video = id.Split('=');
if (video.Length > 1)
id = video[1].ToString();
else
id = video[0].ToString();
}
else
{
if (id.Contains("/"))
{
string[] video = id.Split('/');
id = video[3].ToString();
}
else
{ }
}
string scr = @" ";

scr = scr + @" ";

scr = scr + @" ";

scr = scr + @" ";

scr = scr + @";

scr = scr + @"type='application/x-shockwave-flash' allowscriptaccess='always' ";

scr = scr + @"allowfullscreen='true' width='250' height='220'> ";

scr = scr + @"

"
;
Literal1.Text = scr;
}
Read more ...

Contact Us

Name

Email *

Message *