Posts tagged ‘.Net’

ImageLabel Control for ASP.NET (Potential CAPTCHA Control)

I posted an article to The Code Project for an image control. The basic idea for developing that is to write e-mail addresses as images using various formatting options on web applications.

Labels are generated as images instead of text, to have more privacy without any configurations and without HttpHandlers

ImageLabel is an ASP.NET web control for generating labels as images. You might want to do that for providing security for e-mail crawlers or to disallow copy paste of the text. Many similar controls have implemented as HttpHandlers, so you need more configuration to make them work. However this control does not need any configuration. You just need to use just like any other asp.net control like Label. Almost all of the label formatting options are included, like font size, backcolor, forecolor. Although this is not implemented as a CAPTCHA control, that functionality can easily added to image generation method.

ImageLabel Control at CodeProject

I think it is a good way to understand page and control life cycle using that control, if you are wondered about them. Beside that, if you like the article you can vote for me if you want to :)

Browser View :

imageLabel on Browser

Visual Studio Design View :

ImageLabel on Visual Studio Designer

MsBee, Write Compile Run .Net 1.1 Applications with Visual Studio 2005

I was just willing to write .Net 1.1 applications from Visual Studio 2005. Maybe you may already know but I found that great utility MsBee. You need also .Net Framework 1.1 SDK to make it install and work if you don’t have and surprisingly 1.1 SDK has a size of more than 100Mb.

Anyway, it is good to write .Net Framework 1.1 targeted applications from Visual Studio 2005.

Developing Web Parts for SharePoint 2003 on Developer’s Windows XP

 Installation of Microsoft Sharepoint Services or Microsoft Sharepoint Portal Server requires a Windows Server computer. However it is possible to develop in Windows XP’s. For deployment you definitely need windows server. Since Sharepoint 2003 is based on asp.net 1.1 you can’t use Visual Studio 2005 for developing, you need to have Visual Studio .Net 2003.

One of the sharepoint extensibility features are web parts. You can develop your web parts, connect them and install them to portal server. For developing web parts Microsoft provides Web Part Templates for Visual Studio .NET. However this template is not enough itself, you need to have Microsoft.sharepoint.DLL file in order to develop web parts. Don’t try to find the file on  Sharepoint SDK 1,  because there is no DLLs included. Although the file size is more than 60MB, the SDK only includes the documentation and nothing more. You can find Microsoft.sharepoint.DLL in Microsoft Sharepoint installed Windows Servers’ Assembly Cache.

Just copy the file from the assembly cache to a location that you remember later, and install web part templates for Visual Studio .Net. During the installation it will ask for Microsoft.sharepoint.DLL file, you just need to reference it. Whenever it completes your system will be ready to  develop Web Parts for Sharepoint 2003.

Link to Download details: SharePoint Products and Technologies Templates: Web Part Templates for Visual Studio .NET

XNA Game Studio Express (Beta) Now Available

I am just downloading it. Download it too. You also need to download Visual Studio C# Express as the documentation says. Also for audio you might need Directx SDK, So downloading all of them.

Useful Links

XNA Readme
XNA Team Blog
XNA Forums

Nullable Types – Null-Coalescing Operator ?? in C# .NET 2.0

Nullable types are instances of Nullable structure. This Nullable structure is a generic struct type in base class library. It behaves like value type when it has a value which means that boxing or unboxing occurs. However when it does not have a value, it is null instead of the value types default value, and boxind or unboxing does not occur.

There is a short notation for the generic Nullable structure. The ? operator is used for that purpose.

Nullable<int> i1;
int? i1;

These expressions evaluates the same CLR code.

Sometimes it is definitely needed to have the null value for the value types because sometimes the default value of the value types might be important, in case of database operations for example.

Also a new operator comes to the language. It’s named as coalescing operator, it is just a shorter form of some statements. The operator is ??.  Here is the usage, and what it means for.

I think it makes code simpler but difficult to read. It is like using  ? operator,instead of using if statements.

string name = "test2";
string guessWhat = name ?? "NoName";
string guessWhat ;
if (name != null)
   guessWhat = name;
else
   guessWhat = "NoName";

This code snippet is exactly the same as the previous code snippet.

EXAMPLE

using System;
using System.Collections.Generic;
using System.Text;
 
namespace Nullables
{
    class Program
    {
        static void Main(string[] args)
        {
            int? i1 = null;
            Nullable<int> i2 = null;
            int i3;
 
            if (i1 == null)
                Console.WriteLine("i1 is null");
            if (i2.HasValue)
                Console.WriteLine("i2 is not null");
            if (i3 == null)
                Console.WriteLine("i2 is null");
 
            string name = "test2";
            string guessWhat = name ?? "NoName";
            Console.WriteLine("name is test2 and value of guessWhat is " +guessWhat);
            name = null;
            guessWhat = name ?? "NoName";
            Console.WriteLine("name is null and value of guessWhat is "+ guessWhat);
 
            Console.ReadLine();
 
        }
    }
}

Here is the output of the code.

i1 is null
i2 is null
name is test2 and value of guessWhat is test2
name is null and value of guessWhat is NoName
_

Another hidden .Net Tool usage basics: ilMerge

Ilmerge is a great utility for any .net developer. What it does is basically merge the assemblies. Let’s say you have three dll and one exe file, you can just merge those 4 files to 1 file using ilmerge. 
As a matter of fact, it is easy to use, you don’t need any recompilation or any other modification. You don’t need to provide installers since there is only one file.

Ilmerge exists in two versions one for .Net 1.1 and the other is .Net 2.0

Basic Usage

Usage: ilmerge [/lib:directory]* [/log[:filename]] [/keyfile:filename [/delaysig
n]] [/internalize[:filename]] [/t[arget]:(library|exe|winexe)] [/closed] [/ndebu
g] [/ver:version] [/copyattrs [/allowMultiple]] [/xmldocs] [/attr:filename] [/pu
blickeytokens] [/wildcards] [/zeroPeKind] [/allowDup:type]* /out:filename <prima
ry assembly> [<other assemblies>...]

Although the help explains very well, here is the usage.

C:\Program Files\Default Company Name\ILMergeBinaryDistribution7>Ilmerge /t:exe
/out:outputfile.exe file1.exe file2.dll

/t us used for the output of the file, exe is for a console application, winexe is for windows forms application and library is for the dlls.

/out is for the name of the output file.

the last parameters are the assemblies to be compined. Attention here is that the first one should be the exe one instead of the class library, becuase it merges the following files to the first file.

Advanced Usage

ILmerge is also usable as a class library for your project. What you need to do is to add the ilmerge executable as a reference and use the namespace of it to do some tasks. The class library is very similar to the console commands.