Posts

Showing posts from 2012

shortcut key for \ Backslash

you can generate it by holding ALT + 092

convert Date by Exact Format

To convert Date time by Format string datestring="12/2/2012"; DateTime.ParseExact(datestring, "MM/dd/yyyy", CultureInfo.InvariantCulture);

in clause to match all items

select * from ItemsPackage where ItemId IN (3,5,2) This will be match as OR Expression to make it get ALL item Id you can make it : select PakageId from ItemsPackage where ItemId in (3,5,2) group by PakageId having count(PakageId) = 3 -- Count of In clause (3,5,2)

add days to date Javascript

To add days to javascript use : // days added var days=5; var ms = new Date().getTime() + (86400000 * days); var added = new Date(ms);

Check if variable is 'undefined' or 'null'

to check if javascript variable is undefined or nul use : if(typeof variable_here === 'undefined'){ // your code here. }; OR : if(! variable_here){ // your code here. };

Retrieve Last Inserted Identity

To returns the last IDENTITY value produced on a connection get last Identity your Session added by your Connection if they any trigger add to any other tables it will return it SELECT @@IDENTITY To returns the last IDENTITY value produced on a connection and by a statement in the same scope SELECT SCOPE_IDENTITY() To returns the last IDENTITY value produced in a table it returns the identity value generated for a specific table in any session and any scope SELECT IDENT_CURRENT('tablename') To avoid the potential problems associated with adding a trigger later on, always use SCOPE_IDENTITY() to return the identity of the recently added row in your T SQL Statement or Stored Procedure.

Get URL Parameter "Query strings"

to get paraneter from url string Url = "http://localhost:6109/CANSHOP/GenerateCoupons.aspx?CouponId=1&MemberId=4"; Uri tempUri = new Uri(Url); string sQuery = tempUri.Query; var query = HttpUtility.ParseQueryString(sQuery); string cId = query["CouponId"]; string mId = query["MemberId"];

Generate New (uniqueidentifier) in SQL Server

If you want to generate a new uniqueidentifier in SQL you can simply use the NEWID() function -- Example 1 SELECT NEWID() -- Example 2 DECLARE @EmployeeID uniqueidentifier SET @EmployeeID = NEWID() -- Example 3 INSERT INTO Employees(EmployeeID, Name) VALUES (NEWID(), 'msm2020')

Get Page Path Details and URL

if we have URL Like : http://localhost:96/Cambia3/Temp/Test.aspx?q=item#fragment to get App Path: Request.ApplicationPath result : Cambia3 to get App Path with page name: Request.CurrentExecutionFilePath result : Cambia3/Temp/Test.aspx to get page path: Request.FilePath result : Cambia3/Temp/Test.aspx to get path: Request.Path result : Cambia3/Temp/Test.aspx to get local page path: Request.Url.LocalPath result : Cambia3/Temp/Test.aspx to get absolute path: Request.Url.AbsolutePath result : Cambia3/Temp/Test.aspx to get physical path: Request.PhysicalApplicationPath result : D:\Inetpub\wwwroot\CambiaWeb\Cambia3 to get page with query: Request.RawUrl result : Cambia3/Temp/Test.aspx?query=arg to get url with query: Request.Url.PathAndQuery result : Cambia3/Temp/Test.aspx?query=arg to get url: Request.Url.AbsoluteUri result : http://localhost:96/Cambia3/Temp/Tes...
Image
using Google Infographics more details <img src='https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=Hello%20world' /> result :

parsing currency to decimal

best way to convert "$10" to decimal is: decimal d = decimal.Parse("$45.00", NumberStyles.Currency); OR decimal.TryParse("$45.00", NumberStyles.Currency, culture, out d);

List of Class To XML File ,C#

if you create a collection class that have a list of Class Like : public class Foo { public List BarList { get; set; } } public class Bar { public string Property1 { get; set; } public string Property2 { get; set; } } we can use XmlSerializer to Save Collection to XML File Foo f = new Foo(); f.BarList = new List (); f.BarList.Add(new Bar { Property1 = "abc", Property2 = "def" }); XmlSerializer ser = new XmlSerializer(typeof(Foo)); using (FileStream fs = new FileStream(@"c:\sertest.xml", FileMode.Create)) { ser.Serialize(fs, f); }

XML to List of Class C#

if we have XML file like this : <picturecollection> <photo> <name>One</name> <path>somepath1</path> </photo> <photo> <name>Two</name> <path>somepath2</path> </photo> </picturecollection> we can use This Code to return List of Class XDocument xdoc = XDocument.Load(Server.MapPath(@"\Photo.xml")); List pics = (from xml in xdoc.Elements("PictureCollection").Elements("Photo") select new Pic { PicName = xml.Element("name").Value, TbPath = xml.Element("path").Value }).ToList(); public class Pic { public string PicName {get; set;} public string TbPath { get; set; } }

index of row for ListView

we can get index of current Row By using :

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)

String Format for Double C#

String Format for Double [C#] The following examples show how to format float numbers to string in C#. You can use static method String.Format or instance methods double.ToString and float.ToString . Digits after decimal point This example formats double to string with fixed number of decimal places . For two decimal places use pattern „ 0.00 “. If a float number has less decimal places, the rest digits on the right will be zeroes. If it has more decimal places, the number will be rounded. [C#] // just two decimal places String .Format( "{0:0.00}" , 123.4567); // "123.46" String .Format( "{0:0.00}" , 123.4); // "123.40" String .Format( "{0:0.00}" , 123.0); // "123.00" Next example formats double to string with floating number of decimal places . E.g. for maximal two decimal places use pattern „ 0.## “. [C#] // max. two decimal places String .Format( "{0:0.##}" , 123.4567); ...

Jquery UI Multiselect bind items from codebehind

you can use : $ ( "#<%=ddlTeste.ClientID%>" ). multiselect ({         checkAllText : "All" ,         uncheckAllText : "Clear" ,     noneSelectedText : "Select a country" ,     selectedText : "# item(s) selected" ,     close : function ( event , ui ) {         var values = $ ( "#<%=ddlTeste.ClientID%>" ). val ();         var array_of_checked_values = $ ( "#<%=ddlTeste.ClientID%>" ). multiselect ( "getChecked" ). map ( function () {             return this . value ;         }). get ();         document . getElementById ( "<%=txtHidDataTeste.ClientID%>" ). value = array_of_checked_values ;     } }); var s = $ ( "#<%=ddlTeste.ClientID%>" ). multiselect (); s . val ([ '1' , '2' , '5' ]); $ ( "#<%=ddlTeste.ClientID%>" ). multiselect ( ...

jQuery UI Multiselect widget clear all check boxes

you can use methiods like Methods After an instance has been initialized, interact with it by calling any of these methods: // example: $("#multiselect").multiselect("method_name"); ...which can be found in the widgets  documentation  under  Methods $ ( "#multiselect" ). multiselect ( "uncheckAll" );

check file exist on Server from SQL Query

use Usage: EXECUTE xp_fileexist <filename> [, <file_exists INT> OUTPUT] OR Create a function like so: CREATE FUNCTION dbo . fn_FileExists (@ path varchar ( 512 )) RETURNS BIT AS BEGIN       DECLARE @ result INT       EXEC master . dbo . xp_fileexist @ path , @ result OUTPUT       RETURN cast (@ result as bit ) END ; GO Edit your table and add a computed column (IsExists BIT). Set the expression to: dbo . fn_FileExists ( filepath )

redirect - go to with javascript

you can use  window . location = url ;

Visual Studio setup project, generate an uninstall .

%windir%\system32\msiexec /x {Product Key}

sql server collation conflict

To resolve the collation conflict add following keywords around "=" operator. SELECT ID FROM ItemsTable INNER JOIN AccountsTable WHERE ItemsTable.Collation1Col COLLATE DATABASE_DEFAULT= AccountsTable.Collation2Col COLLATE DATABASE_DEFAULT Collation can affect following areas: 1) Where clauses 2) Join predicates 3) Functions 4) Databases (e.g. TempDB may be in a different collation database_default than the other databases some times)

Getting files by creation date in C#

using System.Linq; DirectoryInfo info = new DirectoryInfo(""); FileInfo[] files = info.GetFiles().OrderBy(p => p.CreationTime).ToArray(); foreach (FileInfo file in files) { // DO Something... }

full screen windows form c#

this .FormBorderStyle = FormBorderStyle.None; this .Left = (Screen.PrimaryScreen.Bounds.Width/2 - this .Width/2); this .Top = (Screen.PrimaryScreen.Bounds.Height/2 - this .Height/2);
Image
Geocode with Google Maps API v3 The purpose of this post is to show how to implement a simple address search tool with auto-completion using Google’s Google Maps API v3 with both client side geocoding and reverse geocoding. The search menu will propose to search for addresses in two ways: the first will be direct address typing with suggestions for auto-completion and the second will finding addresses by dragging a marker on a map. See it working here This is done in 5 steps: create a page and download the jquery libraries initialize a map, a geocoder and a marker setup the jquery search widget to work with the geocoder to fetch suggestions and pin a marker down upon selection of a result configure a listener to reverse geocode marker position when it is being dragged Create a page We start by creating a file structure which includes an index.html file, a css/ and a js/ folders. We need as well to go on the jquery website to download the autocomplete widget library a...

SVN Working Copy ... locked

One approach would be to: Copy edited items to another location. Delete the folder containing the problem path. Update the containing folder through Subversion. Copy your files back. Commit

Full text index search using one-character word

I'm using full text index search. There are few cases when for our customer it is important to find words even with only one character. Unfortunately it seems that SQL server ignores such words, although I haven't found assurance for that in docs. So here is the scenario. Suppose I want to find word 3. My table data are as follows: select * from test_fts ; id txt ----------- -------------------------------------------------- 1 3 trees 2 33 trees 3 green trees Now I'm trying to find the word 3. select * from test_fts where contains ( txt , '"3"' ) id txt ----------- -------------------------------------------------- Informational : The full-text search condition contained noise word ( s ). select * from test_fts where contains ( txt , '"3*"' ) id txt ----------- -------------------------------------------------- 2 33 trees OK 3 is a nois...

Creating Full Text Catalog and Full Text Search - SQL SERVER

Image
SQL SERVER – 2008 – Creating Full Text Catalog and Full Text Search September 5, 2008 by pinaldave Full Text Index helps to perform complex queries against character data.  These queries can include word or phrase searching. We can create a full-text index on a table or indexed view in a database. Only one full-text index is allowed per table or indexed view. The index can contain up to 1024 columns. Software developer Monica who helped with screenshots also informed that this feature works with RTM (Ready to Manufacture) version of SQL Server 2008 and does not work on CTP (Community Technology Preview) versions. To create an Index, follow the steps: Create a Full-Text Catalog Create a Full-Text Index Populate the Index 1) Create a Full-Text Catalog Full – Text can also be created while creating a Full-Text Index in its Wizard. 2) Create a Full-Text Index 3) Populate the Index As the Index Is created and populated, you c...