Posts

Showing posts from November, 2012

index of row for ListView

we can get index of current Row By using : <%# Container.DataItemIndex %>

Session variable and Current Context in .cs File ASP.NET

To read Current Context that contain Request, Response, Session System.Web.HttpContext.Current System.Web.HttpContext.Current.Session["ValueItem"] = "Value";

ASP.NET Get Client IP

To get User IP Address in ASP.NET: HttpContext.Current.Request.UserHostAddress; OR use Request if used inside ASP Page inherited from Page class Request.UserHostAddress;

Get Address,City,County From IP address

First you must create account on  Here  to get API_Key you can read document from Here once you get API_Key you can use Code to get data : private String GetCityName(string IP) { string _City = ""; try { string _URL = null; string _ApiKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; _URL = "http://api.ipinfodb.com/v3/ip-country/?key=" + _ApiKey + "&format=xml&ip=" + IP; //Get google response as XML doc dynamic xmlDoc = new System.Xml.XmlDocument(); xmlDoc.Load(_URL); System.Xml.XmlNode _root = xmlDoc.DocumentElement; System.Xml.XmlNodeList _CityName = xmlDoc.GetElementsByTagName("cityName"); System.Xml.XmlElement _CityNameElement = (System.Xml.XmlElement)_CityName.Item(0); _City = _CityNameElement.FirstChil

Compress & Decompress Gz File using C#

Compress File public static void Compress(FileInfo fileToCompress) { using (FileStream originalFileStream = fileToCompress.OpenRead()) { if ((File.GetAttributes(fileToCompress.FullName) & FileAttributes.Hidden) != FileAttributes.Hidden & fileToCompress.Extension != ".gz") { using (FileStream compressedFileStream = File.Create(fileToCompress.FullName + ".gz")) { using (GZipStream compressionStream = new GZipStream(compressedFileStream, CompressionMode.Compress)) { originalFileStream.CopyTo(compressionStream); Console.WriteLine("Compressed {0} from {1} to {2} bytes.", fileToCompress.Name, fileToCompress.Length.ToString(), compressedFileStream.Length.ToString()); } }

Querying Multiple Columns (Full-Text Search)

SELECT Name, Color FROM Production.Product WHERE CONTAINS((Name, Color), 'Red');

Array contains() or IndexOf in Jquery

To get index of or check if object on array Jquery use : $.inArray(value, array) It returns the index of a value in an array. It returns -1 if the array does not contain the value.

Unique constraint on multiple columns

WE can make it with Table Query CREATE TABLE [dbo].[user]( [userID] [int] IDENTITY(1,1) NOT NULL, [fcode] [int] NULL, [scode] [int] NULL, [dcode] [int] NULL, [name] [nvarchar](50) NULL, [address] [nvarchar](50) NULL, CONSTRAINT [PK_user_1] PRIMARY KEY CLUSTERED ( [userID] ASC ), CONSTRAINT [UQ_codes] UNIQUE NONCLUSTERED ( [fcode], [scode], [dcode] ) ) ON [PRIMARY] OR : ALTER TABLE dbo.User ADD CONSTRAINT ucCodes UNIQUE (focde, scode, dcode)