Welcome to MSDN Blogs Sign in | Join | Help

Wriju's BLOG

.NET and everything
“Good Bye” Thriller - Mike Jackson in Silverlight

King of Pop is no more available as showman to us. We will miss his presence in every bit of our life.

 

Microsoft Silverlight is broadcasting his farewell through Silverlight at http://inmusic.ca/news_and_features/Michael_Jackson

 

“Good Bye” King. We will miss you.

Namoskar!!!

ASP.NET 4.0 : New HTML Snippet

In Visual Studio 2010 we have more than 200+ snippet to make your HTML life easier. It is not just Snippets which you can use, there is Surround with. For example, you want to wrap an area into UpdatePannel, you have surround with option with a mouse click.

 

Couple of shortcuts,

 

button - which will create

<asp:Button ID="Button1" Text="text" runat="server" />

 

There are many more. You may also use mouse button to write your HTML code just like C#/VB.NET.

 

Namoskar!!!

Visual Basic 10 : Line Continuation Magic

There are some new enhancements in Visual Basic 2010 or Visual Basic 10 where you can really have greater flexibility on how you handle multiple lines for continuous statements,

 

'Explicit Continious Line (no need to use & _ )

Dim sContinuation As String =

    "Hey you know I can write multiple lines without & _"

 

Console.WriteLine(sContinuation)

 

 

'Multiple statements in a single line

Dim sMessage As String = "Hello Visual Basic 10" : Console.WriteLine(sMessage)

 

Namoskar!!!

NotifyIcon : Display Windows Form in System Tray

While talking to different people I get this question. And in Visual Studio it is very easy to do,

 

You need Windows Forms Application, then drag and drop NotifyIcon there. Set one icon with that control so that it is visible,

 

public partial class Form1 : Form

{

    public Form1()

    {

        InitializeComponent();

    }

 

    private void Form1_Load(object sender, EventArgs e)

    {

   

        notifyIcon1.BalloonTipText = "Current Time : " + DateTime.Now.ToString();

        notifyIcon1.BalloonTipTitle = "This is Test";

 

        //Keep the Baloon for 1 second

        notifyIcon1.ShowBalloonTip(1000);

 

        //Start the window in Minimized Mode

        WindowState = FormWindowState.Minimized;

 

    }

 

 

    //While minimizing the Form show only in System Tray

    private void Form1_Resize(object sender, EventArgs e)

    {

        if (FormWindowState.Minimized == WindowState)

        {

            Hide();

        }

    }

 

    //Restore the Form State Back to normal

    private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)

    {           

        WindowState = FormWindowState.Normal;

        Show();

    }       

}

 

Namoskar!!!

 

Hello Azure in Talking Tech - Chennai 13 June 2009

"Hello Azure" at Chennai last week end was fun. I showed the demo and successfully uploaded it to Microsoft Cloud CTP. WOW, with a funky Internet connection outside office it is indeed a challenge. Received so many questions and fun to interact after the session.

IMG_0895

IMG_0897

IMG_0902

Namoskar!!!

Presenting Windows Azure in Talking Tech 2009

I am currently back from New Delhi where I have presented Windows Azure – Microsoft Cloud Computing. This Saturday I am going to Chennai for the same purpose. In Delhi (actually in Gurgaon) I enjoyed the interactivity where people had lots of questions. Just wanted to face many more of such opportunities to help Developer community.

IMG_0724

Enjoy my Azure App at http://wriju.cloudapp.net/. Hope to see you there.

Namoskar!!!

Visual Studio 2010 and .NET Framework 4 Training Kit - May Preview

 

Available at http://www.microsoft.com/downloads/details.aspx?FamilyID=752CB725-969B-4732-A383-ED5740F02E93&displaylang=en

 

Namoskar!!!

VB.NET 10 : Automatic Property

Now in VB.NET 10 we have automatic property,

Public Property myName As String = "Test"

Sub Main()

        Console.WriteLine(myName)

End Sub

In ildasm it shows like,

image

Namoskar!!!

 

Azure : Pricing & Licensing Overview

Should you have question, please visit http://www.microsoft.com/azure/pricing.mspx

How will Microsoft charge for the Azure Services Platform?

Subject to certain limits, Azure Services will be available without charge during our Community Technology Preview (CTP). Once Microsoft Azure launches for commercial use, we will offer a portfolio of services and you will be billed according to your actual consumption of each service. Based on feedback during the CTP period, pricing offers may be provided based on the following parameters.

·         Windows Azure - Compute and Storage services

·         .NET Services - Access Control, Service Bus, and/or Workflow Services

·         SQL Services- Database service for LOB applications

·         SharePoint Services (future) - SharePoint components that developers can utilize and build into their application

How will resource utilization be measured?

Monitoring agents in the Azure platform will measure specific resource utilization. However, no specific pricing or consumption models will be announced until we have received sufficient input from the user community and partners during the CTP period. This will include:

·         CPU time, measured in CPU-hours

·         Bandwidth for ingress/egress from the data center, measured in GBs

·         Storage, measured in GBs

·         Transactions, measured as requests likes Gets & Puts

How can I get support?

Microsoft will offer these services both a la carte as well as through our established business programs. Regardless of how you purchase Microsoft services, you will have access to our extensive field organization and our rich partner ecosystem. In addition, you will be able to get support through our standard support channels. We will also give you access to robust service level agreements and guarantees on quality of service.

How Can I Get Started With Azure?

·         Current Timeframe – Community Technology Preview (CTP) Program

o    Explore and experiment with the Azure SDKs locally

o    Register to try the CTP.

 

·         Availability Timeframe – H2 2009

o    Acquire directly through the Microsoft Online Customer Portal

o    Acquire though ISVs (independent software vendors): purchase an ISV application which utilizes the Azure Services Platform, and pay the ISV through their own licensing and pricing model

 

Namoskar!!!

Visual Studio 2010 : Multi Targeting

Like Visual Studio 2008, in Visual Studio 2010 also we have multi-target. So ideally you can create project targeting Framework 2.0, 3.0, 3.5 and 4.0. This behaviour is little different here. Earlier, we have Framework 3,5 carrying both 2.0 and 3.0. So in Visual Studio 2008 it was just the intellisense alter and control load filter. Now in this version of Visual Studio 2010 we do have Framework 4.0 and 3.5 side-by-side support. Now based on your selection it loads CLR version 2.0 or 4.0.

We love Visual Studio.

Namoskar!!!
ADO.NET Entity Framework v2 : ExecuteStoreQuery

There is now an option in ADO.Net Entity Framework v2 for us to execute store query,

 

IEnumerable<Customer> custs =  ctx.ExecuteStoreQuery<Customer>("SELECT * FROM Customers", null);

 

foreach (var c in custs)

{

    Console.WriteLine(c.CustomerID);

   

}

 

Namoskar!!!

 

Visual Studio 2010 and .NET Framework 4 Beta 1 Walkthroughs

Watch out the videos on Visual Studio 2010 at http://msdn.microsoft.com/en-us/teamsystem/dd441784.aspx

Here are some of them,

Ø  Dynamic Programming in Visual C# and Visual Basic

 

Ø  Office Programmability in Visual C# and VisualBasic

 

Ø  Test-driven Development with Generate From Usage

 

Ø  F# in Visual Studio 2010

 

Ø  Deploying Multiple Office Solutions in a Single ClickOnce Installer

 

Ø  Copying a Document to the End User Computer after a ClickOnce Installation

 

Ø  How to Target a Specific .NET Framework Version or Profile

 

Ø  How to Write a Parallel.For Loop with Thread-Local Variables

 

Ø  How to Create and Execute a Simple PLINQ Query

 

Ø  Using Task Groups to Improve Performance

 

Ø  Implementing Futures

 

Ø  Debugging a Parallel Application

 

Namoskar!!!

LINQ to CSV : Getting data the way you want

Getting data from CSV is one of the mostly used business in applications/tools development.

Here how we can do it in LINQ,

You have a table called Emp with the below details,

CREATE TABLE [dbo].[Emp](

      [Id] [int] IDENTITY(1,1) NOT NULL,

      [FirstName] [varchar](50) NOT NULL,

      [LastName] [varchar](50) NULL,

 CONSTRAINT [PK_Emp] PRIMARY KEY CLUSTERED

(

      [Id] ASC

)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]

) ON [PRIMARY]

Now you may want to get the CSV out of it. To do that you can save the query output to a .csv file.

The contents of that csv would look like,

1,Wriju,Ghosh

10,Writam,Ghosh

11,Debajyoti,Ghosh

12,Sumitra,Ghosh

82,Tupur,Sanyal

 

So when you get a single line you can Split() them with a comma (,). The code is very simple,

string[] allLines = File.ReadAllLines(@"E:\Temp\Emp.csv");

 

var query = from line in allLines

            let data = line.Split(',')

            select new

            {

                ID = data[0],

                FirstName = data[1],

                LastName = data[2]

            };

 

foreach (var s in query)

{

    Console.WriteLine("[{0}] {1} {2}", s.ID, s.FirstName, s.LastName);

}

Namoskar!!!

Setup and Deployment : Custom Action to Capture User Input

Purpose

Users are allowed to pass Product Key while installing in .msi. During that we want to capture it for registration to avoid piracy.

Challenges

When we use “Customer Information” dialog in “Start” action, it has “SerialNumberTemplate”. But capturing information from there is really tough as mentioned in the article http://support.microsoft.com/kb/253683/en-us. So we have to use the “TextBoxes” dialog and get the data from there.

How

For sample test, I have created on Windows Forms Application “Deployment_SerialNumber”. There I have added InstallerClass called “InstallHelper.cs” with the below code

[RunInstaller(true)]

public partial class InstallerHelp : Installer

{

    public override void Install(IDictionary stateSaver)

    {

        base.Install(stateSaver);

 

        string strKey = Context.Parameters["KeyValue"];

 

        string sPath = @"c:\Test.txt";

       

        if (File.Exists(sPath))

            File.Delete(sPath);

       

       

        File.WriteAllText(sPath, strKey);

    }

}

Now I moved to Setup and Deployment Project which is in the same Solution. Added the Primary Output under Application Folder of File System. Pointed the Windows Application “Deployment_SerialNumber”.

image

Then from the Visual Studio menu I have moved to User Interface of Setup project.

image

Then in the “Start” section I have added TextBoxes(A) and placed between “Installation Folder” and “Confirm Installation”.

image

In the property window I made the other two text boxes to invisible.

 

image

Then moved to “Custom Actions” by VS menu,

image

Then under “Install” added the Project where I have the InstallHelper.cs class.

image

Then we have added the “Custom Action Data” to pass the user input through parameter. That is the catch and because of this we can capture it through string strKey = Context.Parameters["KeyValue"];

Notice the Property and the code. Both has “KeyValue

image

One caution, The value you pass here cannot be with a space, it will fail (because you are passing parameter).

Namoskar!!!

 

LINQ to XML : Understanding Annotations

Annotations are used for private use. It does not directly associated and known as Black Box in XML world. This can also be considered as meta tag.

Below is an example on how it can be handled. I have created a sample Windows Applications and will try to capture my understanding.

/// <summary>

/// Class for the Structure of the Data

/// </summary>

public class DataClass

{

    public int ID { get; set; }

    public string Name { get; set; }

    public string Email { get; set; }

}

 

public static XElement xmlData = new XElement("family");

private void Form2_Load(object sender, EventArgs e)

{

    //Create a List in memory

    List<DataClass> lstData = new List<DataClass>

    {

        new DataClass(){ID = 1, Name = "Debajyoti", Email = "d@contoso.com"},

        new DataClass(){ID = 2, Name = "Sumitra", Email = "s@contoso.com"},

        new DataClass(){ID = 3, Name = "Wriju", Email = "wg@contoso.com"},

        new DataClass(){ID = 4, Name = "Tupur", Email = "t@contoso.com"},

        new DataClass(){ID = 5, Name = "Writam", Email = "w@contoso.com"},

    };

 

    //Here create the XML which will hold the info also an annotation

    foreach (DataClass data in lstData)

    {

        XElement member = new XElement("member",

            new XAttribute("ID", data.ID),

            new XAttribute("Name", data.Name));

       

        //Adding Annotation to the element

        member.AddAnnotation(data.Email);

 

        xmlData.Add(member);               

    }

 

    //Loading the List holding two values ID and Name

    listBox1.DataSource = lstData;

    listBox1.DisplayMember = "Name";

    listBox1.ValueMember = "ID";

 

}

 

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)

{

    if (listBox1.SelectedIndex > 0)

    {

        //By ID we will capture the element to get the annotation

        var email = xmlData.Descendants("member").

            First(el => el.Attribute("ID").Value == listBox1.SelectedValue.ToString());

 

        //Get the annotation to print that out.

        label1.Text = email.Annotations<String>().First();

    }

}

Namoskar!!!

More Posts Next page »
Page view tracker