Thursday, September 16, 2010

Firefox addon for View state size of ASP.Net page

ViewstateSize is a Firefox add-on which displays the size of the viewstate on the current asp.net page you are seeing.

Details about this add-on is available in the following link

https://addons.mozilla.org/en-US/firefox/addon/5956/

Sunday, June 13, 2010

COM Interop with silverlight 4.0

Silverlight 4 has a feature for accessing COM components which is installed /available in client machines.
I will walk through how to access a Excel application through silvelight .
For developing this application , we need VS 2010 , Silverlight 4 SDK.
Create a silverlight project using VS2010
image
Take the properties of SL project under silverlight tab for enabling Out Of Browser support.
image
We need to check ‘require elevated permission’ under Out of browser settings button.
Now am creating a datagrid(dgName) in MainPage.xaml and binding some data.
below code is used for setting datasource to datagrid.
private void UserControl_Loaded(object sender, RoutedEventArgs e)
       {
           ModelClass m = new ModelClass();
           dgName.ItemsSource = m.SetDataSource();
       }
image
preview : data grid.
Now i am putting a button which invokes ‘excel’ application and write all the data from the above data grid to the excel app.
private void Button_Click(object sender, RoutedEventArgs e)
       {
           dynamic excelObj = AutomationFactory.CreateObject("Excel.Application");
           excelObj.Visible = true;
           // add a workbook to the instance  
           dynamic workbook = excelObj.workbooks;
           workbook.Add();
           dynamic sheet = excelObj.ActiveSheet;
           sheet.Name = "Sample Sheet";
           // get the active sheet  
           dynamic cell = null; int i = 1;
           // iterate through our data source and populate the excel spreadsheet 
           foreach (ModelClass item in dgName.ItemsSource)
           {
               cell = sheet.Cells[i, 1]; // row, column   
               cell.Value = item.ID;
               cell.ColumnWidth = 25;
               cell = sheet.Cells[i, 2];
               cell.Value = item.Name;
               i++;
           }
       }
we are using AutomationFactory ( static class under System.Windows.Interop) for invoking Excel app . we can use this class for invoking apps like ‘Outlook’ , ‘Text to Speech’ COMs’.
‘dynamic’ is object whose operations will be resolved at run time.Intellisence will not be available while coding using ‘dynamic’ object.
image
I am attaching a sample application , can be download from here

Sunday, June 6, 2010

Bing Map integration with ASP.Net



Describes a sample application for showing your location using bing map api.
Step 1 .
Create an ASP.Net web site.
Step 2.
Include <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"></script> in header part of aspx page.
Include these functions for initializing and locating bing map
<script type="text/javascript">
      var map;       
      function LoadMap() {
          map = new VEMap('myMap');
          map.LoadMap();
      }
      function StartGeocoding(address) {
          map.Find(null,    // what
                      address, // where
                      null,    // VEFindType (always VEFindType.Businesses)
                      null,    // VEShapeLayer (base by default)
                      null,    // start index for results (0 by default)
                      1,    // max number of results (default is 10)
                      null,    // show results? (default is true)
                      null,    // create pushpin for what results? (ignored since what is null)
                      null,    // use default disambiguation? (default is true)
                      null,    // set best map view? (default is true)
                      GeocodeCallback);  // call back function
      }
      function GeocodeCallback(shapeLayer, findResults, places, moreResults, errorMsg) {
          // if there are no results, display any error message and return
          if (places == null) {
              //alert((errorMsg == null) ? "There were no results" : errorMsg);
              return;
          }
          var bestPlace = places[0];
          // Add pushpin to the *best* place
          var location = bestPlace.LatLong;
          var newShape = new VEShape(VEShapeType.Pushpin, location);
          //var desc = "Latitude: " + location.Latitude + "<br>Longitude:" + location.Longitude;
          newShape.SetTitle(bestPlace.Name);
          map.AddShape(newShape);
      }
      function locate()
      {
        var obj= document.getElementById('txtAddress');
        if(obj !=null)
        {
        LoadMap();
        StartGeocoding(obj.value);
        }
      }
</script>
Step 3 .
Create a div area for displaying map control.
add a text box for accepting address and a button for invoking locate() JS function included in the page.


Sample application can be downloaded from here

Monday, May 31, 2010

Creating a Basic Application Using the Silverlight Map Control





Create a Silverlight Project

To begin, create a Silverlight project in Visual Studio.
  1. Open Visual Studio 2008.
  2. Select File the main menu.
  3. Select New, and then Project from the menu.
  4. In the New Project dialog box, under the language of your choice (for example, Visual C#), select Silverlight.
  5. Select a Silverlight Application from the available templates and then click OK.
    clip_image002
  6. When asked, make sure the Host the Silverlight application in a new Web site option is checked. Because of URL access restrictions in Silverlight, your Web page must be hosted using the HTTP scheme for it to be able to access Bing Maps tiles. For more information about Silverlight URL access restrictions, see http://msdn.microsoft.com/en-us/library/cc189008(VS.95).aspx.
    clip_image003
Display a Map

Next, reference the map control dlls in your project and display the default map in your application.
  1. With the Silverlight project selected (not the Web project), select Project then Add Reference from the Visual Studio main menu.
  2. In the Add Reference dialog box, click the Browse tab.
  3. Browse to the location of your Bing Maps Silverlight Control installation. Open the Libraries folder, select the Microsoft.Maps.MapControl.dll and the Microsoft.Maps.MapControl.Common.dll files and click OK.
  4. Add the map control assembly to MainPage.xaml of your Silverlight project by creating a namespace in your UserControl. The MainPage.xaml now looks like this:
<UserControl x:Class="SilverlightApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl">
<Grid x:Name="LayoutRoot">
</Grid>
</UserControl>
  1. Once the map control assembly is referenced, then you can add the map element <m:Map/> to your page. Put this element within the Grid.
  2. To authenticate your use of the map control, you also need to set credentials. To do this, add a CredentialsProvider attribute to the <m:Map/> element. Set the CredentialsProvider attribute to the Bing Maps Key that you obtained from the Bing Maps Account Center. Your final MainPage.xaml looks like this:
<UserControl x:Class="SilverlightApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl">
<Grid x:Name="LayoutRoot">
<m:Map CredentialsProvider="your key"/>
</Grid>
</UserControl>
  1. Run your Silverlight Map Control application to display a default map.
Change the Map Mode using XAML

To customize the map or other UIElements, you can set properties in your MainPage.xaml file.
  1. To change the mode, or style, of the map, set the Mode of the map element to “Aerial”. Your MainPage.xaml now looks like this:
<UserControl x:Class="SilverlightApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl">
<Grid x:Name="LayoutRoot" Background="White">
<m:Map CredentialsProvider="your key" Mode="Aerial" />
</Grid>
</UserControl>
Now run your project to see the map in Aerial mode.
Change the Map Mode using C#

Alternatively you can use Visual C# to change the map mode.
  1. Start by giving your map element a name so that you can access this element from within C#. Your MainPage.xaml will look like this:
<UserControl x:Class="SilverlightApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl">
<Grid x:Name="LayoutRoot" Background="White">
<m:Map CredentialsProvider="your key" Name="myMap" />
</Grid>
</UserControl>
  1. Then in your MainPage.xaml.cs file, reference the map control namespace with a using statement.
  2. Finally, set the map mode when the MainPage is constructed. Your MainPage.xaml.cs file now looks like:
using System.Windows.Controls;
using Microsoft.Maps.MapControl;
namespace SilverlightApplication1
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
myMap.Mode = new AerialMode();
}
}
}
  1. Now run your project to see the map in Aerial mode.

You can download sample application Click here

Sunday, May 9, 2010

Methods for Debugging SQL Server queries

 

 

There are three ways to debug SQL Server 2005 queries

  • Direct DataBase debugging.
  • Application debugging
  • Debugging from a DB project

Debugging a Stored Procedure via Direct Database Debugging
Direct Database Debugging is the simplest way to debug a SQL Server 2005 stored procedure. From Visual Studio's IDE you can opt to step into a stored procedure and then step through each of its statements one at a time, inspecting and changing T-SQL variables and parameters within the stored procedure. The download at the end of this article includes a SQL Server 2005 Express Edition version of the Northwind database. I added a stored procedure called DoThings that takes a @CategoryID parameter as input and then displays all products in that category whose price is greater than the average if at least 25% of the products in the category cost more than the average. If less than 25% of the products cost more than the average, then all of the products in the category that cost less than the average are displayed. A silly stored procedure for sure, but it has a number of T-SQL statements and variables and an input parameter, all of which will help illustrate some of the debugging features.

To step into the DoThings stored procedure, navigate to the Server Explorer window, drill down into the stored procedures, right-click on the DoThings node and choose the "Step Into Stored Procedure" option from the context menu. (Note: SQL Server debugging support is only available in the Team Systems and Professional editions of Visual Studio.)

This will start the debugger and execute the stored procedure. Since DoThings expects a @CategoryID value passed in, a dialog box prompts us to provide this value. Enter the value 1 and click OK.

Execution will start at the first statement. You can step from statement-to-statement using the Step Into or Step Over commands (F11 or F10 on the keyboard, respectively), as well as add parameters and variables to the Watch window. The screenshot below shows the stored procedure while being stepped through. The yellow arrow in the margin in the left indicates what statement is currently being executed. The Watch window shows the values and types of @CategoryID and @AvgPrice.

After the stored procedure completes, the results can be viewed through the Output window.

As you can see, Direct Database Debugging is very easy to launch, use, and understand. Simply right-click on a stored procedure from the Server Explorer, choose the "Step Into Stored Procedure" option, and you're off and running.

Debugging a Database Object from a Running Application
Direct Database Debugging makes it easy to debug a stored procedure directly from within the Visual Studio IDE. In some cases, however, we would rather start debugging a database object when it is called from an ASP.NET application. This would allow us to better understand when a particular database object was invoked and its state.

This style of debugging is referred to as Application Debugging. To use this style of debugging we need to perform the following steps:

  • Add breakpoints to the database object(s) that you want to debug. A database object will only be debugged if it contains a breakpoint. For example, you cannot "Step Into" a stored procedure from application code that calls the stored procedure. Rather, you must explicitly set a breakpoint within the stored procedure itself.
  • Configure the application to debug SQL Server objects. As we will see shortly, this is as simple as checking a checkbox.
  • Update the connection string to disable connection pooling. Connection pooling is a performance enhancement that allows an application to connect to a database from an existing pool of connections. This feature, if enabled, does not correctly construct the debugging infrastructure needed on the connection taken from the pool. Since connection pooling is enabled by default, we must update our connection string to disable connection pooling during the timeframe that application debugging is being used. (After you've completed debugging the SQL Server objects via application debugging be sure to reinstate connection pooling.)
Let's tackle each of these steps one at a time.

First, open the DoThings stored procedure in Visual Studio and set a breakpoint on the first statement (DECALRE @AvgPrice money). One task down, two to go!

To configure the ASP.NET application to support SQL Server debugging, right-click on the Project name in the Solution Explorer and choose the Property Pages from the context menu. This will bring up the dialog box shown below. Go to the Start Options tab and check the "SQL Server" checkbox in the Debuggers section. Two tasks down, one to go!

Lastly, we need to update the connection string used by the application to disable connection pooling. To accomplish this simply tack on the attribute Pooling=false to you existing connection string. Assuming the connection string information is defined within Web.config's <connectionStrings> section, you would update the connection string value like so:

<connectionStrings>
    <add name="NorthwindConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\NORTHWND.MDF;Integrated Security=True;User Instance=True; Pooling=false" providerName="System.Data.SqlClient"/>
</connectionStrings>

All three tasks have now been completed! To test the application debugging, create an ASP.NET page that invokes the DoThings stored procedure. The demo available for download at the end of this article has such a page. When debugging the ASP.NET application and visiting this page, the breakpoint in the stored procedure is hit and control is delegated to the debugger. Once in the debugger we can step through the stored procedure's statements and view and edit the parameter values and variables through the Watch window, just like with Direct Database Debugging.

 

This post is based on http://blogs.msdn.com/sqlclr/archive/2006/06/29/651644.aspx and 4guysfromrolla

Wednesday, May 5, 2010

Rounded corners using CSS [with out Images]

 

This post is completely based on pure Html and css.

the implementation is completely based on mathematics – geometry :-)

to achieve this we need to write some hack in xhtml as

<div class="container">
<b class="rtop"><b class="r1"></b> <b class="r2"></b> <b class="r3"></b> <b class="r4"></b></b>
Curved coners with out images !!!!!!!!! <b class="rbottom"><b class="r4"></b> <b class="r3"></b> <b class="r2"></b> <b class="r1"></b></b>
</div>


we are putting multiple <b> tags by means of creating different lines with descending widths.


now come the css implementation ,


 we are setting different width settings for <b> tags. as 


.r1{margin: 0 5px}
.r2{margin: 0 3px}
.r3{margin: 0 2px}
.r4{margin: 0 1px; height: 2px}




i.e. r1 , the top <b> tag has less width and more margin compared to the below one.



Attaching sample source code also with this post  https://docs.google.com/leaf?id=0B9WPg7HFu_8dNGU2NGU3YzItOWVhNC00NTEzLThmYWEtMTM3NzVmNDk4ZTM4&sort=name&layout=list&num=50



Sample Preview :Clipboard01

Monday, April 26, 2010

Customizing Fiddler for Omniture scripts

 

 

One of the best ways to investigate your Omniture implementation is to watch the actual traffic that is being sent by your site. To assist with this, Omniture provides a JavaScript debugger (search “Debugger” in the SiteCatalyst Knowledge Base). But sometimes, you need to break out the good ol’ packet sniffer to watch the actual traffic being sent.

The trouble with Fiddler is that it will watch all of your requests, making it difficult to isolate the Omniture requests that you’re looking for.

Fortunately, you can configure a custom filter in Fiddler, which will exclude non-Omniture calls. This makes is more convenient to use Fiddler to look at server requests sent to Omniture. Creating the filter is a little bit geeky, but very easy to do. Here’s how you do it:

1. Open Fiddler


2. From the Main Menu, select Rules > Customize Rules…

 

3. Add the following code to the class handlers. This adds the menu item, and turns it on by default.

public static RulesOption("&Omniture Only")
var m_OmnitureOnly: boolean = true;

4. Add the following code to the static function OnBeforeRequest. This is the logic for the filter. It tells Fiddler to only include requests that match the pattern 2o7.net. You can change the filter value by changing the value of var re.

if (m_OmnitureOnly){
  var re = /2o7.net/;
    if (!re.test(oSession.host)){ 
         }
}

5. Fiddler will now show you only Omniture requests, as long as the “Omniture Only” rule is selected in the Rules menu.

Once you have configured Fiddler to show you the Omniture server requests, be sure to check out the Debugger white paper in the SiteCatalyst knowledge base for more information on what the different parameters mean.

Thursday, April 22, 2010

Cool Fire Fox Addons:

 

Web Developer

The Web Developer extension adds a menu and a toolbar to the browser with various web developer tools

https://addons.mozilla.org/en-US/firefox/addon/60

 

Firebug

  • Inspect HTML and modify style and layout in real-time
  • Use the most advanced JavaScript debugger available for any browser
  • Accurately analyze network usage and performance
  • Extend Firebug and add features to make Firebug even more powerful
  • Get the information you need to get it done with Firebug.

https://addons.mozilla.org/en-US/firefox/addon/1843

DOM Inspector

Inspects the structure and properties of a window and its contents with a variety of views.

https://addons.mozilla.org/en-US/firefox/addon/6622

Monday, April 19, 2010

Auto-Implemented Properties in VB.Net

 

Auto-implemented properties enable you to quickly specify a property of a class without having to write code to Get and Set the property. When you write code for an auto-implemented property, the Visual Basic compiler automatically creates a private field to store the property variable in addition to creating the associated Get and Set procedures.

With auto-implemented properties, a property, including a default value, can be declared in a single line. The following example shows three property declarations.

 

Public Property Name As String
Public Property Owner As String = "DefaultName"
Public Property Items As New List(Of String) From {"M", "T", "W"}
Public Property ID As New Guid()

An auto-implemented property is equivalent to a property for which the property value is stored in a private field. The following code example shows an auto-implemented property.

 

Property Prop2 As String = "Empty"

The following code example shows the equivalent code for the previous auto-implemented property example.

 

Private _Prop2 As String = "Empty"
Property Prop2 As String
Get
Return _Prop2
End Get
Set(ByVal value As String)
_Prop2 = value
End Set
End Property

Backing Field






When you declare an auto-implemented property, Visual Basic automatically creates a hidden private field called the backing field to contain the property value. The backing field name is the auto-implemented property name preceded by an underscore (_). For example, if you declare an auto-implemented property named ID, the backing field is named _ID. If you include a member of your class that is also named _ID, you produce a naming conflict and Visual Basic reports a compiler error.

The backing field also has the following characteristics:



  • The access modifier for the backing field is always Private, even when the property itself has a different access level, such as Public.



  • If the property is marked as Shared, the backing field also is shared.



  • Attributes specified for the property do not apply to the backing field.



  • The backing field can be accessed from code within the class and from debugging tools such as the Watch window. However, the backing field does not show in an IntelliSense word completion list.


Initializing an Auto-Implemented Property






Any expression that can be used to initialize a field is valid for initializing an auto-implemented property. When you initialize an auto-implemented property, the expression is evaluated and passed to the Set procedure for the property. The following code examples show some auto-implemented properties that include initial values.

 

Property FirstName As String = "James"
Property PartNo As Integer = 44302
Property Orders As New List(Of Order)(500)

You cannot initialize an auto-implemented property that is a member of an Interface, or one that is marked MustOverride.

When you declare an auto-implemented property as a member of a Structure, you can only initialize the auto-implemented property if it is marked as Shared.

When you declare an auto-implemented property as an array, you cannot specify explicit array bounds. However, you can supply a value by using an array initializer, as shown in the following examples.

 

Property Grades As Integer() = {90, 73}
Property Temperatures As Integer() = New Integer() {68, 54, 71}

Friday, April 16, 2010

Pagination Query with SQL Server 2005

 
Pagination can be done more easier through SQL queries.

CREATE Procedure Paging  @startIndex int , @endIndex int
AS
Begin
-- create the Common Table Expression, which is a table called "pagination"
with pagination as
(
    -- your normal query goes here, but you put your ORDER BY clause in the rowNo declaration
    select
        row_number() over (order by department, employee) as rowNo,
        -- a list of the column you want to retrieve
        employeeId, employee, department
    from
        Employee
    where
        disabled = 0
)
-- we now query the CTE table
select
    -- add an additional column which contains the total number of records in the query
    *, (select count(*) from pagination) as totalResults
from
    pagination
where
    RowNo between @startIndex and @endIndex
order by
    rowNo

End

If we want to see 50 to 60 records using paging query , just execute exec Paging  5,6 --> will return rows from 50 to 60.

Advantages : we doesn’t need to keep all records in memory by means of datasources , we can hold records corresponding to a particular page.

Silverlight 4.0 released with a bunch of new features

New features:

* XAP Signing : User cannot unpack zap files any more !!
* Custom window chrome for trusted applications
* Pinned full-screen mode : can view application in full screen mode , even if it is hosted in a browser.
* WCF RIA Services Toolkit
* ContextMenu control : right click and do the thing you want :-)
* SLLauncher silent installs

Enhanced features:
* RichTextBox improvements
* WebBrowser control
* Printing API enhancements
* Native automation (COM interop)
* Language/Script support
* Networking and Sockets
* User consent dialog on webcam/clipboard/etc.

more information available @ http://www.microsoft.com/silverlight/

Monday, April 12, 2010

Data Caching in ASP.Net

Cached Data Reference Pattern

Whenever an attempt is made to access data from the cache, it should be with the assumption that the data might not be there any more. Thus, the following pattern should be universally applied to your access of cached data. In this case, we're going to assume the object that has been cached is a DataTable.

public DataTable GetCustomers(bool BypassCache)
{
string cacheKey = "CustomersDataTable";
object cacheItem = Cache[cacheKey] as DataTable;
if((BypassCache) || (cacheItem == null))
{
cacheItem = GetCustomersFromDataSource();
Cache.Insert(cacheKey, cacheItem, null,
DateTime.Now.AddSeconds(GetCacheSecondsFromConfig(cacheKey),
TimeSpan.Zero);
}
return (DataTable)cacheItem;
}

There are several points I'd like to make about this pattern:

  • Values, like cacheKey, cacheItem and the cache duration, are defined once and only once.
  • The cache can be bypassed as needed—for example, after registering a new customer and redirecting to a list of customers, it would probably be best to bypass the cache and repopulate it with the latest data, which would include the newly inserted customer.
  • Cache is only accessed once. This has performance benefits and ensures that NullReferenceExceptions don't occur because the item was present the first time it was checked but had expired before the second check.
  • The pattern uses strong type checking. The "as" operator in C# will attempt to cast an object to a type and will simply return null if it fails or if the object is null.
  • The duration is stored in a configuration file. All cache dependencies, whether file-based, time-based, or otherwise, should ideally be stored in a configuration file so that changes can be made and performance measured easily. I also recommend that a default cache duration be specified, and that the GetCacheSecondsFromConfig() method uses the default if no duration is specified for the cacheKey being used.