Monday, 5 March 2012

Select with Case Example in MS-SQL Server

SELECT [t0].[ProductID], ...
FROM [dbo].[Products] AS [t0]
LEFT OUTER JOIN [dbo].[Categories] AS [t1] ON [t1].[CategoryID] = [t0].[CategoryID]
WHERE (
    (CASE
        WHEN [t1].[CategoryName] = @p0 THEN
            (CASE
                WHEN [t0].[UnitsInStock] < @p1 THEN 1
                WHEN NOT ([t0].[UnitsInStock] < @p1) THEN 0
                ELSE NULL
             END)
        ELSE CONVERT(Int,
            (CASE
                WHEN NOT ([t0].[Discontinued] = 1) THEN 1
                WHEN NOT NOT ([t0].[Discontinued] = 1) THEN 0
                ELSE NULL
             END))
     END)) = 1

Css Browser Hacks

/* for IE6 */
*html .someClass {color:red}
/* for IE7 */
*:first-child + html .someClass {color:red}
/* inline IE7 CSS */
.someElement {
   color:blue; /* all browsers */
   *color:red;
}

/* inline IE7 CSS */
.someElement {
   color:blue; /* all browsers */
   //color:red;
/* IE7 browser */
}

/* inline IE8 CSS */
.someElement {
  color:crimson; /* all browsers */
  color:black\0/; /* IE 8 & 9 */
}
/* IE9 CSS */
:root .someElement { color:green\0/IE9; }  /* IE9 */

/* FireFox 3 and Up */
html>/**/body .someClass, x:-moz-any-link, x:default {left:1em !important}

@media screen and (-webkit-min-device-pixel-ratio:0)
{
   .someElement 

    {
         margin:1em
    }
}

Thursday, 1 March 2012

Validating file types of Doc / Docx / Pdf / Jpeg / Bmp / Gif / Png by regular expression

^.+\.(?:(?:[dD][oO][cC][xX]?)|(?:[pP][dD][fF]))$
Will accept .doc, .docx, .pdf files having a filename of at least one character:
^           = beginning of string
.+          = at least one character (any character)
\.          = dot ('.')
(?:pattern) = match the pattern without storing the match)
[dD]        = any character in the set ('d' or 'D')
[xX]?       = any character in the set or none 
              ('x' may be missing so 'doc' or 'docx' are both accepted)
|           = either the previous or the next pattern
$           = end of matched string
 Similarly you can validate any file type as the above,
For JPG / BMP / Gif :
(.*\.([Jj][Pp][Gg])|([Bb][Mm][Pp])|([Gg][Ii][Ff])|([Pp][Nn][Gg])$)
Validating For Email:-
^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|
  (([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$
Validating USA Phone No.
((\(\d{3}\) ?)|(\d{3}[-.]))?\d{3}[-.]\d{4}( ext\d{0,}) 
it will accept as: 123.456.7890 
or
123-456-7890 or 123.456-7890(1 hyphen and 1 dot)
You can test it here: http://www.regextester.com/ 
 You can embed case insensitity into the regular expression like so: 
 \.(?i:)(?:jpg|gif|doc|pdf)$

The GDI code for converting the string to image and displaying as a Link in C#


using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class CsharpImage : System.Web.UI.Page
{
 protected void Page_Load(object sender, EventArgs e)
 {
   string str = string.Empty;
     for (int i = 0; i < 5; i++)
      {
         Bitmap bmp = new Bitmap(74, 16, PixelFormat.Format64bppArgb);
         using (Graphics g = Graphics.FromImage(bmp))
          {
            g.SmoothingMode = SmoothingMode.AntiAlias;
            Font font = new Font("Tahoma", 12, FontStyle.Regular, GraphicsUnit.Pixel);
                g.FillRectangle(Brushes.Transparent, new RectangleF(0, 0, bmp.Width, bmp.Height));
                        g.FillRectangle(Brushes.White, 0, 0, bmp.Width, bmp.Height);
                         str = "Sudarsan-" + i ;
                        g.DrawString(str, font, new SolidBrush(Color.Black), 1, 1);
                        bmp.Save(Server.MapPath("~/images/"+i+".jpg"), ImageFormat.Jpeg);
                  }
           }
           
  for (int i = 0; i < 3; i++)
  {
   Response.Write(string.Format("<a href='{0}'><img src='images/{0}.jpg'/></a><br/>", i));
  }
 }
}

Centering a Div in the centre of the Screen Using JQuery

jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
    this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
    return this;
}


//We can call the method as follows:
$("#popup").center();

Friday, 24 February 2012

How to Increse the Upload size of a file in ASP.Net 2.0

Some it is there to Upload a File of higher size to the server, 
but .net 2.0 upload control doesn't allows it make it to take
higher file size just go your web config and find the <configuration>
then <System.web> and inside it write the code below. You need to change
the Execution time and maxRequestLength as per your need.
here the default file size it can take is of 4mb and the time out is of 90 
seconds.
Even if some one uploads file of more size it will throw the error.
So in your try catch block check <Fileupload Control ID >.PostedFile.ContentLenth not be
more than the maxRequestLength given in the <httpRuntime> of the web.config file of 
your project.
 <httpRuntime
executionTimeout = "110" [in Seconds][number ]
maxRequestLength = "4096" [number] 
requestLengthDiskThreshold = "80" [number]
useFullyQualifiedRedirectUrl = "false" [true|false]
minFreeThreads = "8" [number]
minLocalRequestFreeThreads = "4" [number]
appRequestQueueLimit = "5000" [number]
enableKernelOutputCache = "true" [true|false]
enableVersionHeader = "true" [true|false]
apartmentThreading = "false" [true|false]
requireRootedSaveAsPath = "true" [true|false]
enable = "true" [true|false]
sendCacheControlHeader = "true" [true|false]
shutdownTimeout = "90" [in Seconds][number]
delayNotificationTimeout = "5" [in Seconds][number]
waitChangeNotification = "0" [number]
maxWaitChangeNotification = "0" [number]
enableHeaderChecking = "true" [true|false]
/> 
Refer the links:
1) http://www.dotnetspark.com/kb/1269-file-upload-control-asp-net-with-codings.aspx 
2)http://msdn.microsoft.com/en-us/library/e1f13641%28v=vs.71%29.aspx

Thursday, 23 February 2012

Opacity for IE-7 and IE-8

filter:Alpha(Opacity=40);/* IE7 and under */
-ms-filter: "Alpha(Opacity=40)"; /* IE8 */

How to use Gradient Effect for IE-7 and IE-8

use these two lines in the ID or class where you required the Effect. 
 
filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#ededed')/* ie7 */
-ms-filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#ededed')/* ie8 */

How to set the display:inline-block in IE-7

 
Here is the Trick to do it 
zoom1/* ie7 hack for display:inline-block */

How to Check Wheather a Video URL is valid or not


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) 
      {
           //Url not valid
           return false;
      }
  }
}