Saturday, April 28, 2012

How to add days in Date in ASP.NET

DateTime dt=new DateTime();
dt=System.DateTime.Now.Date;
dt.AddDays(2);

How To Resize image in asp.net at upload

 System.Drawing.Image imageToBeResized = System.Drawing.Image.FromStream(FleUpPhoto.PostedFile.InputStream);
                    int imageHeight = imageToBeResized.Height;
                    int imageWidth = imageToBeResized.Width;
                    int maxHeight = 240;
                    int maxWidth = 320;
                    imageHeight = (imageHeight * maxWidth) / imageWidth;
                    imageWidth = maxWidth;

                    if (imageHeight > maxHeight)
                    {
                        imageWidth = (imageWidth * maxHeight) / imageHeight;
                        imageHeight = maxHeight;
                    }

                    Bitmap bitmap = new Bitmap(imageToBeResized, imageWidth, imageHeight);
                    System.IO.MemoryStream stream = new MemoryStream();
                    bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                    stream.Position = 0;
                    byte[] image = new byte[stream.Length + 1];
                    stream.Read(image, 0, image.Length);

 SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["Connect"]);

 SqlCommand storeimage = new SqlCommand("INSERT INTO TablePic" + "(Content, ImgType, Size,imageSeen) " + " values (@image, @imagetype, @imagesize,@imgSeen)", myConnection);
                   
                    storeimage.Parameters.Add("@image", SqlDbType.Binary, image.Length).Value = image;
                    storeimage.Parameters.Add("@imagetype", SqlDbType.VarChar, 100).Value = FleUpPhoto.PostedFile.ContentType;
                    storeimage.Parameters.Add("@imagesize", SqlDbType.BigInt, 99999).Value = FleUpPhoto.PostedFile.ContentLength;
                    storeimage.Parameters.Add("@imgSeen", SqlDbType.VarChar, 100).Value = "Off";
                       myConnection.Open();
                    storeimage.ExecuteNonQuery();
                    myConnection.Close();

Thursday, April 26, 2012

Open new page as a popup window in asp.net



<script type="text/javascript" language="javascript">
        function changeScreenSize(w, h) {
            window.resizeTo(w, h)
        }
</script>

call this script at body onload
<body onload="changeScreenSize(500,300)" >

</body>

Tuesday, April 24, 2012

How to check nullify in SQL SERVER

Select * from TblEmp where address IS NULL


Select * from TblEmp where address IS NOT NULL

Update TblEmp set empcode='E021' where address IS NOT NULL 

How To Disabled right click,copy and paste in asp.net

Define in body tag at design side in asp.net

<body oncontextmenu="return false;" onload="start()" onselectstart="return false;" oncopy="return false;" onpaste="return false;">