Skip to main content

Posts

Showing posts from May, 2012

Get latitude - longitude by postal code

This is a service from geoname.org . You can download various type of DB files about pincode/ IP Addresses and much more, and the real cool about this is, they provide it for free I have included a iFrame here for Demo, You can test it here. 1.select country 2. put your city's zip code 3. click a outside the postal-code textbox 4. It will populate areas of city in next input box. select anyone of them n you will get lat long for the area geoname.org provides many geolocation related services also that you can integrate with your websites or apps. Here is the link of the page where geonames has its services and other data sources : http://download.geonames.org/export/

Geolocation by area/city name

Hi its again about the Geo-location , but its inverse Geo-location   actually I was googling for a question: how to get lat long by city name ?  OR  how to get lat long by address ? and got this one working and simply awesome  :  http://ws.geonames.org/search?name=ujjain&country=in&type=xml Add caption This will return you XML  that will contain lat- long for that are with some other city related information. you just have to extract the lat- long from this xml. be lazy... be awesome :)

Geolocation using ip address

Here is a method for C-sharp lovers, It will fetch the IP Address of Client and some other browser info of the host when you run it after compiling your code. We are just creating Http Request and an object of HttpBrowserCapabilities class. Now with this object we can collect all the host specific data that we will send to service to get the Geolocation of the host. private string UserLogEntry(string flag) { String publicIpAddress = HttpContext.Current.Request.UserHostAddress.ToString(); HttpBrowserCapabilities oBrowserCap = Request.Browser; String browserName = oBrowserCap.Browser.ToString(); String version = oBrowserCap.Version.ToString(); String majorVersion =oBrowserCap.MajorVersion.ToString(); String minorVersion =oBrowserCap.MinorVersion.ToString(); String platform = oBrowserCap.Platform.ToString(); String isBeta = oBrowserCap.Beta.ToString(); String isCrawler =oBrowserCap.Crawler.ToString(); ...

How to get Browser detail in c# asp.net

With any HttpRequest through our Asp.Net application we can collect a lot information about client's browser. We can get this information creating an object of the Browser property of the Request . we can access many properties with this object like: Browser.Type, Browser.Name, Browser.Version etc. Find the code below for an example: private void Button1_Click( object sender, System.EventArgs e) { System.Web.HttpBrowserCapabilities browser = Request.Browser; string s = "Browser Capabilities\n" + "Type = " + browser.Type + "\n" + "Name = " + browser.Browser + "\n" + "Version = " + browser.Version + "\n" + "Major Version = " + browser.MajorVersion + "\n" + "Minor Version = " + browser.MinorVersion + "\n" + "Platform = ...

Page init event in asp.net

Init is actually a event which is available for every individual control on a Asp.Net page. So you can use this event for any of the control on your page or use it for Page as well. Page_Init event is fired before the Page_Load, We can perform here task related to user authentication and change master page applied to the page. This may also be useful for changing theme of the pages. protected void Page_Init(object sender, EventArgs e) { int LoginId = Convert.ToInt32(SqlHelper.ExecuteScalar(Config.ConnectionStringName, "Check_User_Logged_In", Convert.ToInt32(Session["LoginUserId"]),Convert.ToString(Session.SessionID))); if (LoginId == 0) { Session.Abandon(); Server.Transfer("Default.aspx"); } } If you are not done yet MSDN's Reference waiting for you.

how to pass null value in sql from c#

Its a very common scenario when we do not pass any value for a column during db insert it places NULL there for that column. But sometimes situation occurs when we programatically want to insert a NULL for a perticular column in table. And this the way to do this : Just use DBNull.Value in place of the value for that column. Check a tiny example, here I want to update a log table, i am updating the User Id and Session Id, and want to set other values to be NULL . string msg = (string)SqlHelper.ExecuteScalar(Config.XcatLinkAccountDB, "spInsertUpdateLog", Convert.ToInt32(Session["LoginUserId"]), Convert.ToString(Session.SessionID), DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, flag);

string.split in c#

Whenever we have a situation where we have to split a string on the basis of a character, we can use this method. First of all we have to check if that char(needle) exists in the string. We are doing it with indexOf method that tells about the index of the char(needle) in string. Then we have to just apply split method , that break the string in an array or strings from the index of the needle-char Let say we have a simple string "I am the_winner" String Result = "I am the_winner"; // now check if if there is  "_" and split to get user Id if (Result.IndexOf("_") != -1) { string[] arr = new string[2]; arr = Result.Split('_'); console.writeline(arr[0].ToString() + " only " + arr[0].ToString()); } The code broke the string from index of the underscore(_) and created array of strings. Output will be : I am the only winner

How to get last inserted id in sql server

SELECT @@IDENTITY It returns the last IDENTITY value produced on a connection, regardless of the table that produced the value, and regardless of the scope of the statement that produced the value. @@IDENTITY will return the last identity value entered into a table in your current session. While @@IDENTITY is limited to the current session, it is not limited to the current scope. If you have a trigger on a table that causes an identity to be created in another table, you will get the identity that was created last, even if it was the trigger that created it. SELECT SCOPE_IDENTITY() It returns the last IDENTITY value produced on a connection and by a statement in the same scope, regardless of the table that produced the value. SCOPE_IDENTITY(), like @@IDENTITY, will return the last identity value created in the current session, but it will also limit it to your current scope as well. In other words, it will return the last identity value that you explicitly created, rather than...

Date difference in C#

We have to create an object of the TimeSpan Class to get difference between two dates or time. Then use the Subtract method of TimeSpan Class to get the difference. You can use Days, Hours, Minutes and Seconds property of the TimeSpan Class to get flexible results. // current date time DateTime d1 = DateTime.Now; // or can get date from DB by converting it into datetime DateTime d2 = new DateTime(2004, 06, 16); //create a timespan object to get the difference between dates ( d1 - d2 ) TimeSpan ts = d1.Subtract(d2); //Timespan has days, hours, years, seconds, minutes etc which can be used as below int hours = (ts.Days * 24) + ts.Hours; some Reference Links are here if you could not understand my grammer http://stackoverflow.com/questions/4946316/showing-difference-between-two-datetime-values-in-hours http://www.dotnetspider.com/forum/539-Date-Difference-C.aspx http://msdn.microsoft.com/en-us/library/8ysw4sby.aspx

String IndexOf method c#

we use IndexOf simply to see whether the input string contains a string. We want to see if the string in the example contains "lucky". Program that uses IndexOf [C#] using System; class Program { static void Main() { // A. // The input string. const string s = "I am lucky."; // B. // Test with IndexOf. if (s. IndexOf ("lucky") != -1) { Console.Write("string contains 'lucky'"); } Console.ReadLine(); } } Output string contains 'lucky' Description. In part A, it has an input string. This string is what we want to test. In part B, it calls IndexOf. IndexOf returns the location of the string 'lucky'. It is not equal to -1, so the line is written to the console window.