Ramani Sandeep's Blog

DotNetting – Fast , Easy Way of Developing Applications

Archive for December, 2009

IIS URL Rewriting and ASP.NET routing

Posted by Ramani Sandeep on December 29, 2009

With the release of URL-rewrite module for IIS 7.0 and the inclusion of ASP.NET routing into the .NET Framework 3.5 SP1, there have been a lot of questions from ASP.NET developers about how these two features relate to each other and when to use each. The intention of this document is to describe the differences between these two technologies and to provide guidance for Web developers on when to use IIS URL rewriting and when to use ASP.NET routing.

From a high-level point of view, it may seem that these technologies provide very similar functionality–both allow your Web applications to have user-friendly and search-engine-friendly URLs. However, there are fundamental differences between these two technologies that are important to understand in order to make the right choice when deciding what to use for your Web application. In order to help you understand those, we will first explain how IIS URL rewriting and ASP.NET routing work.

Read more

Posted in ASP.NET 3.5 | Tagged: , , , | Leave a Comment »

string to date conversion asp.net

Posted by Ramani Sandeep on December 28, 2009

There has been always a Problem in working DateTime variable in ASP.NET when you are working on different environments.

So I feel that why not make some short of solution for that. Here i came up with some result. May be there is better alternative.

Create one common class or if you have in your project than all you need to create is static method to convert string into DateTime with ‘MM/dd/yyyy’ Format.

public static DateTime ParseDateFormatToMMDDYYYY(string oDate)
    {
        IFormatProvider fp = new System.Globalization.CultureInfo("en-US");
        return DateTime.ParseExact(oDate, "MM/dd/yyyy", fp);
    }

Once you have created static method now all you have to do is to use it when ever necessary.

 DateTime search_date = Utilities.ParseDateFormatToMMDDYYYY(Request.QueryString["searchDate"].ToString());

Here the format for Date can be Controlled from Utility Class you can make changes as per your requirement.

Hope this will help !!!

Shout it
kick it on DotNetKicks.com

Posted in Uncategorized | Tagged: , , , | Leave a Comment »

e-Commerce using ASP.NET MVC Framework

Posted by Ramani Sandeep on December 18, 2009

In this two-part series, you will learn how to a typical front end of an e-commerce system using the great Microsoft ASP.NET MVC 1.0 framework.

In the first part, we will focus upon the following points:

  • system design
  • functionality design
  • architecture design and
  • database design etc…

In the second part, we will discuss the detailed coding related things.

Introduction

With the rapid development of Internet, online book sales, as a typical example of the development of Web e-commerce systems, have been deeply mixed up with people’s daily life. Staying at home, people can choose to buy their own favorite variety of books, which greatly shortens the buying time and improves efficiency. Across time and spatial constraints to business circulation, online book sales system has not only brought great changes in commercial circulation, but also brought conveniences to consumers.

Based on the famous MVC design pattern, Microsoft ASP.NET MVC provides a design framework and technical foundation for creating web applications under the .NET platform. It is a lightweight, highly testable framework, which combines the existing excellent ASP.NET characteristics (such as the Master pages, etc.).

It is worth noting that ASP.NET MVC framework has greatly simplified the complex part of programming inside the ASP.NET Web forms solution; and, at the same time, whether the strength or flexibility are concerned, they are not inferior to the latter at all.

In this two-part series, we will construct a client side of an online book sales system using the ASP.NET MVC framework.

Read more

Shout it

kick it on DotNetKicks.com

Posted in ASP.NET MVC | Tagged: , , , | 5 Comments »

How to dynamically adjust an iframe’s height?

Posted by Ramani Sandeep on December 16, 2009

Last day when I was using iframe in one of my project , i came across one problem & I have solved it now.

so I think why not to share with you all. I was looking to display content of the other aspx page inside iframe but i wasnt able to adjust the height of the iframe. so try out this solution to resolve it.

Insert iframe on page

   <iframe scrolling='no' frameborder='0' id='frmid' src=’getad.aspx'
            onload='javascript:resizeIframe(this);'>
   </iframe>

Use this javascript to resize iframe based on the height & width of child page

<script language="javascript" type="text/javascript">
 function resizeIframe(obj)
 {
   obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
   obj.style.width = obj.contentWindow.document.body.scrollWidth + 'px';                        
 }
 </script>

What does this code do? When the body of the parent frame loads, it looks up the document element “childframe” which corresponds to the iframe. Then the page calls a function resizeFrame(). The function sets the height of the frame to be the scrollHeight, which effectively removes the scrollbar.

Hope this will help !!!

kick it on DotNetKicks.com

Shout it

Posted in Css, JavaScript | Tagged: , , , | 29 Comments »

Lazy Loading

Posted by Ramani Sandeep on December 11, 2009

Introduction

Lazy loading is a design pattern commonly used in computer programming to defer initialization of an object until the point at which it is needed. It can contribute to efficiency in the program’s operation if properly and appropriately used. The opposite of lazy loading is Eager Loading.

Article – 1: jQuery Tabs and Lazy Loading by Malcolm Sheridan

In this article I will connect to the Northwind database using LINQ to SQL, and display customer and product information in separate tabs. I’ll also show you one way of lazy loading these tabs so the data is retrieved only once, not each time a tab is selected.

Read more

Article – 2: Lazy Loading jQuery Tabs with ASP.NET by Mikesdotnetting

This article looks at efficient use of jQuery tabs when displaying data. Specifically, it covers how to lazy-load data, so that it is only accessed and displayed if the tab is clicked.

Lazy Loading is a well-known design pattern that is intended to prevent redundant processing within your application. In the case of tabbed data, there seems little point retrieving and binding data that appears in a tabbed area that no one looks at. So, this examples covers how to defer data access and display until the user wants it – which is defined by them clicking the relevant tab.

Read more

Article – 3: Eager Loading and Lazy Loading in ADO.NET Data Services by Gil Fink

The default behavior of a data service’s .NET client is not to load the entities’ associated objects. When we request an entity we will get it from the service but its associated objects will not load up at all.

Lets say that I have two entities in my program

  • a course
  • a department

The associations between the entities are that a department can have a lot of courses and a course belongs to one department.

When I load a department it’s list of courses will be empty. trying to iterate the list of courses will give nothing because the courses will not load until we tell them to be loaded explicitly.

This is done by the LoadProperty method of the data service context.

Read more

 

I have a great learning experience thru this.

Now its your turn to have it.

kick it on DotNetKicks.com
Shout it

Posted in ASP.NET, ASP.NET 3.5, ASP.NET Ajax, C# 3.0, JQuery, Linq | Tagged: , , , , , , , | Leave a Comment »

Introducing the Microsoft Visualization Language

Posted by Ramani Sandeep on December 11, 2009

Vedea is a prototype of a new experimental language for creating interactive infographics, data visualizations and computational art. 

It is designed to be accessible to people who are either new to programming or whose primary domain of expertise is something other than programming. 

Microsoft wanted to give those users a tool that they can use to realize their own vision and visualizations without having to engage skilled programmers, but have it be an environment that skilled programmers would not find limiting.

for more information visit :

Posted in Mics | Tagged: , , | Leave a Comment »

Capture web page as image using ASP.NET

Posted by Ramani Sandeep on December 5, 2009

Introduction

This article describes how you can take a screenshot of a special webpage programmatically with ASP.NET. The goal of this sample is to find a way to capture a webpage’s image. The parameter is just a special url. Only by knowing this url we want to be able to take a screenshot of this webpage – a bitmap of what the user would see if he/she types this url in the browser.

How to take a screenshot of browser-content?

Here I have used one utility program to take screen shot of browser content name is IECapt.exe. IECapt is a small command-line utility to capture Internet Explorer’s rendering of a web page into a BMP, JPEG or PNG image file. We have to put IECapt.exe on the server and define that we have the right to execute it.

Download IECapt.exe

Here is the sample application for the same.

Step 1: Create the web application with two web page & in first page create screen like this

1

Here is the html for that:

 <table cellpadding="10" cellspacing="0" width="700" style="border-style:solid; background-color:green;">
            <tr>
                <td align="center" colspan="2">
                    <h1>
            Take a Snap of Web page</h1> <hr />
                </td>
            </tr>
            <tr>
                <td align="right">
                    Url:
                </td>
                <td align="left">
                    <asp:TextBox ID="txtUrl" runat="server" Width="300">http://www.ramanisandeep.wordpress.com</asp:TextBox>
                </td>
            </tr>
            <tr>
                <td align="right">
                    Width:
                </td>
                <td align="left">
                    <asp:TextBox ID="txtWidth" runat="server">500</asp:TextBox>
                </td>
            </tr>
            <tr>
                <td align="right">
                    Height:
                </td>
                <td align="left">
                    <asp:TextBox ID="txtHeight" runat="server">500</asp:TextBox>
                </td>
            </tr>
            <tr>
                <td align="right">
                    Save image with this name :
                </td>
                <td align="left">
                    <asp:TextBox ID="txtDestImage" runat="server">MyImage3</asp:TextBox>
                </td>
            </tr>
            <tr>
                <td align="right">
                </td>
                <td align="left">
                    <asp:Button ID="btnCapture" runat="server" OnClick="btnCapture_Click" Text="Capture"
                         />
                </td>
            </tr>
        </table>

Step 2: On Button click event call the class method & redirect to new page to show the image

Code behind would be like this:

 protected void btnCapture_Click(object sender, EventArgs e)
    {
        int Width, Height;
        Width = Convert.ToInt32(txtWidth.Text);
        Height = Convert.ToInt32(txtHeight.Text);
        CaptureWebPage cwp = new CaptureWebPage();
        string imagePath = cwp.GetImage(txtUrl.Text, txtDestImage.Text, Server.MapPath("~"), Width, Height);
        Response.Redirect("~/Default2.aspx?Path=" + imagePath);
    }

Step 3: Create class CaptureWebPage.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Diagnostics;
using System.Drawing.Imaging;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;

public class CaptureWebPage
{
    private const string EXTRACTIMAGE_EXE = "IECapt.exe";
    private const int TIMEOUT = 60000;
    private const string TMP_NAME = "InBetween.png";

    public CaptureWebPage()
    {
    }

    private void Shot(string url, string rootDir)
    {
        Process p = new Process();
        p.StartInfo.FileName = rootDir + "\\" + EXTRACTIMAGE_EXE;
        p.StartInfo.Arguments = String.Format("\"{0}\" \"{1}\"", url, rootDir + "\\" + TMP_NAME);
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.CreateNoWindow = false;
        p.Start();
        p.WaitForExit();
        p.Dispose();
    }

    private System.Drawing.Image Scale(System.Drawing.Image imgPhoto,int Width, int Height)
    {
        int srcWidth = imgPhoto.Width;
        int srcHeight = imgPhoto.Height;
        int srcX = 0; int srcY = 0;
        int destX = 0; int destY = 0;

        float percent = 0; float percentWidth = 0; float percentHeight = 0;

        percentWidth = ((float)Width / (float)srcWidth);
        percentHeight = ((float)Height / (float)srcHeight);

        if (percentHeight < percentWidth)
        {
            percent = percentWidth;
            destY = 0;
        }
        else
        {
            percent = percentHeight;
            destX = 0;
        }

        int destWidth = (int)(srcWidth * percent);
        int destHeight = (int)(srcHeight * percent);

        System.Drawing.Bitmap bmPhoto = new System.Drawing.Bitmap(Width,
                Height, PixelFormat.Format24bppRgb);
        bmPhoto.SetResolution(imgPhoto.HorizontalResolution,
                imgPhoto.VerticalResolution);

        Graphics grPhoto = Graphics.FromImage(bmPhoto);
        grPhoto.InterpolationMode =
                InterpolationMode.HighQualityBicubic;

        grPhoto.DrawImage(imgPhoto,
            new Rectangle(destX, destY, destWidth, destHeight),
            new Rectangle(srcX, srcY, srcWidth, srcHeight),
            GraphicsUnit.Pixel);

        grPhoto.Dispose();
        return bmPhoto;
    }

    public string GetImage(string url, string name, string rootDir,	int width, int height)
    {
        string fileName = rootDir + "\\" + TMP_NAME;
        Shot(url, rootDir);
        System.Drawing.Image thumbImage = System.Drawing.Image.FromFile(fileName);
        Scale(thumbImage, width, height);
        System.Drawing.Image scaledImg = Scale(thumbImage, width, height);
        fileName = rootDir + "\\" + name + ".png";
        if (File.Exists(fileName))
            File.Delete(fileName);
        scaledImg.Save(fileName, ImageFormat.Png);
        return name + ".png";
    }
}

Step 4: Create new page Default2.aspx to display the shot taken

Here is the html for that:

 <asp:Image ID="theImage" runat="server" />
  <asp:Button ID="Button1" runat="server" Text="Go Back" OnClick="Button1_Click" />

Code behind would be:

 protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["Path"] != null)
        {
            theImage.ImageUrl = "~//" + Request.QueryString["Path"].ToString();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Default.aspx");
    }

Step 5: Most important thing is Download IECapt.exe from the above link & put at the rool level.

Run the Application

2

Great !!!

Now enjoy taking the snap of the web page in your web application when ever required or application demands.

Jay Ganesh

Shout it

kick it on DotNetKicks.com

Posted in ASP.NET, C# 2.0 | Tagged: , , , , , , , , , , | 20 Comments »

CodeRun Web Toolkit: C# to JavaScript web framework

Posted by Ramani Sandeep on December 3, 2009

What is CodeRun Web Toolkit?

CodeRun Web Toolkit (CWT) is a complete framework for creating Rich Internet Applications with C#. CWT provides the following components:

  • C# to JavaScript converter
  • C# to JavaScript remoting handler
  • Rich UI library, loosely modeled after WPF (Windows Presentation Foundation)

You can use CodeRun Web Toolkit to:

  • Implement client side scripts for existing ASP.NET applications with C#
  • Work with external JavaScript libraries (such as YUI) in C#.
  • Develop compelling and optimized AJAX Applications in C#

CodeRun Web Toolkit Added Features

Language Features

  • Namespaces
  • Classes
  • Interfaces
  • Properties
  • Events
  • Method Overloads
  • Polymorphism
  • Extension Methods
  • Delegates
  • Indexers
  • Generics
  • LINQ
  • Reflection and Attributes
  • Object Initializers

Productivity Features (in Visual Studio)

  • Compilation Error Reporting
  • Code Coloring
  • Code Refactoring
  • Performance Profiling

Toolkit Features

  • Ajax as method calls
  • Rich UI Library

Simple code example

The following example demonstrates how to write a simple C# method and use CodeRun Web Toolkit to convert it to JavaScript:

//Demonstrates how to execute a C# class at the browser
namespace CWT_Samples
{
  public partial class SimpleExample : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
     {
       this.RegisterRunAtClientScripts(SimpleExample_Client.Main, head, body);
     }
   }

  //The following class will be converted to JavaScript
  [RunAtClient]
  public class SimpleExample_Client
  {
     public static void Main()
     {
        var window = HtmlDom.Window;
        window.alert("Hello from C#!");
     }
  }
}

for more information – click here

Posted in C# 2.0, JavaScript | Tagged: , , | 1 Comment »

Pranav Mistry: The thrilling potential of ‘SixthSense’ technology

Posted by Ramani Sandeep on December 3, 2009

At TEDIndia, Pranav Mistry demos several tools that help the physical world interact with the world of data — including a deep look at his SixthSense device and a new, paradigm-shifting paper "laptop".

In an onstage Q&A, Mistry says he’ll open-source the software behind SixthSense, to open its possibilities to all.

Watch the video – click here

About the Genius

Pranav Mistry is a PhD student in the Fluid Interfaces Group at MIT’s Media Lab. Before his studies at MIT, he worked with Microsoft as a UX researcher; he’s a graduate of IIT. Mistry is passionate about integrating the digital informational experience with our real-world interactions.

Some previous projects from Mistry’s work at MIT includes intelligent sticky notes, Quickies, that can be searched and can send reminders; a pen that draws in 3D; and TaPuMa, a tangible public map that can act as Google of physical world. His research interests also include Gestural and Tangible Interaction, Ubiquitous Computing, AI, Machine Vision, Collective Intelligence and Robotics.

to know more about him : click here

Posted in Mics | Tagged: , , | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.

Join 317 other followers