Skip to main content

Posts

Showing posts from May, 2012

Create a thumbnail in ASP.NET

 #region Create Thumbnail     // Create a thumbnail in byte array format from the image encoded in the passed byte array.       // (RESIZE an image in a byte[] variable.)       public static byte[] CreateThumbnail(byte[] PassedImage, int LargestSide, int Height, int Width)     {         byte[] ReturnedThumbnail;         using (System.IO.MemoryStream StartMemoryStream = new System.IO.MemoryStream(), NewMemoryStream = new System.IO.MemoryStream())         {             // write the string to the stream               StartMemoryStream.Write(PassedImage, 0, PassedImage.Length);             // create the start Bitmap from the MemoryStream that contains the image               System.Drawing.Bitmap startBitmap = new System.Drawing.Bitmap(StartMemoryStream);             // set thumbnail height and width proportional to the original image.               int newHeight;             int newWidth;             double HW_ratio;             if (startBitmap.Height > startBitmap.

Adjust iframe

<%-- <script language="JavaScript"> <!-- function autoResize(id){     var newheight;     var newwidth;     if(document.getElementById){         newheight=document.getElementById(id).contentWindow.document .body.scrollHeight;         newwidth=document.getElementById(id).contentWindow.document .body.scrollWidth;     }     document.getElementById(id).height= (newheight) + "px";     document.getElementById(id).width= (newwidth) + "px"; } //-->                                             </script>                                             <iframe src="Control/ShowItem.aspx" id="iframe1" marginheight="0" frameborder="0"height="45px;"                                                 width="250px" onload="autoResize('iframe1');"></iframe>--%>                                                                                       <

Understanding Paths in ASP.NET

There are more than 30 methods in ASP.NET classes that deal with paths and/or URLs. Many developers coming from traditional ASP tend to stick with the methods they know from ASP (which are still there), but there are many other useful methods that can save you a lot of time and headache. Fritz Onion covers the details of managing paths and URLs in ASP.NET, looking at everything from virtual to physical path mapping to root path reference syntax. A quick scan of the classes in the System.Web.* hierarchy reveals more than 30 methods that deal with paths and/or URLs. In this article, I will cover the more commonly used path and URL functions in ASP.NET—presenting what they do, how they work, and when to use them. The best way to understand what each of these functions and properties do is to try them out and review the results. I have prepared a page that makes calls to the most commonly used path functions and properties in ASP.NET, which you can download from http://staff.develo

Get URL and Execute

Get URL of ASP.Net Page in code-behind and Hit external url from code-behind string path = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/"); string strURL = path + @"Control/ShowItem.aspx"; System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(strURL); request.Timeout = 99999; System.IO.StreamReader sr = new System.IO.StreamReader(request.GetResponse().GetResponseStream()); string response = sr.ReadToEnd(); sr.Close(); Response.Write(response);

How to resize an image in byte[] ?

  This code creates a byte[] that contains an image into a byte[] that contains an image of a different size.  At this point it does create a byte array of the proper size, and it inserts a new row into the table.   I created the code that reads it back out of the table and displays it on the ASP.NET page.  The image displays as it should, which verifies that it is properly encoded in the new byte array.  #region Create Thumbnail     // Create a thumbnail in byte array format from the image encoded in the passed byte array.       // (RESIZE an image in a byte[] variable.)       public static byte[] CreateThumbnail(byte[] PassedImage, int LargestSide, int Height, int Width)     {         byte[] ReturnedThumbnail;         using (System.IO.MemoryStream StartMemoryStream = new System.IO.MemoryStream(), NewMemoryStream = new System.IO.MemoryStream())         {             // write the string to the stream               StartMemoryStream.Write(PassedImage, 0, PassedImage.Length)

Add Dynamic Row In Grid

-------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------- <div>         <br />         No. of&nbsp; Person :         <asp:DropDownList ID="ddl" runat="server" AutoPostBack="True"             onselectedindexchanged="ddl_SelectedIndexChanged">         <asp:ListItem Text="1" />         <asp:ListItem Text="2" />         <asp:ListItem Text="3" />         <asp:ListItem Text="4" />         </asp:DropDownList>         <asp:GridView ID="Gridview1" runat="server" ShowFooter="True"             AutoGenerateColumns="False" BackColor="White" BorderColor="#999999"             BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines=&quo

Adding Dynamic Rows in ASP.NET Gridview

To get started, let’s grab a GridView control from the Visual Studio Toolbox and put it in the Web Form. The mark up would look something like this: Source Code:- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default16.aspx.cs" Inherits="Default16" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">     <title>Untitled Page</title> </head> <body>     <form id="form1" runat="server">     <div>         <asp:gridview ID="Gridview1" runat="server" ShowFooter="true" AutoGenerateColumns="false">             <Columns>             <asp:BoundField DataField="RowNumber" HeaderText="Row Number" />

Encrypt and Decrypt String ASP.NET

You can Encrypt and Decrypt string  variable like QueryString etc by FormsAuthentication class. This class is Derived from System.Web.Security. This is a simple method to encryption and decryption. I think the code will definitely explain how it works. if anyone want detailed description just drop a comment i will reply ASAP. First Initializes a new instance of  FormsAuthenticationTicket class, this ticket is used to encrypt via FormsAuthentication.Encrypt(FormsAuthenticationTicket tk) method. FormsAuthentication.Encrypt method return encrypted string. FormsAuthenticationTicket has three parameters.parameters are  string name, bool isPersistent, and int timeout.The time, in minutes, for which the authentication ticket is valid. if isPersistent is true if the ticket will be stored in a persistent cookie (saved across browser sessions); otherwise, false. If the ticket is stored in the URL, this value is ignored. Encrypt Method       private string Encrypt(s

Rounding up datetime to nearest half an hour

-- An SQL User defined function to round off date time -- to nearest half an hour point                         CREATE FUNCTION RoundOffHours ( @myTime datetime ) RETURNS datetime AS BEGIN         DECLARE @RoundedTime datetime         SELECT @RoundedTime =         dateadd ( minute ,         CASE          WHEN ( datepart ( minute , @myTime )) BETWEEN 0 AND 14                 THEN 0          WHEN ( datepart ( minute , @myTime )) BETWEEN 15 AND 30                 THEN 30          WHEN ( datepart ( minute , @myTime )) BETWEEN 31 AND 44                 THEN 30          WHEN ( datepart ( minute , @myTime )) BETWEEN 45 AND 60                 THEN 60         END ,         dateadd ( minute , - datepart ( minute , @myTime ), @myTime )         )         RETURN @RoundedTime END -- Usage :           SELECT dbo . RoundOffHours ( '2010-05-11 10:01' )           SELECT dbo . RoundOffHours ( '2010-05-11 10:14' )           SELECT dbo . R