Archive for the ‘ASP.Net’ Category.

JSON Tools for .NET

JSON (JavaScript Object Notation) is a lightweight data-interchange format. JSON is an object notation in text format that Javacript engine fully understands and there is no need to parse for it.

The library contains some basic types that Javascript requires. IJSONObject, JSONElement, JSONNumber<T>, JSONString, JSONBoolean, JSONCollection, JSONArray and JSONObject.

  • JSONObject : Represents JSON objects beginning and ending with curly braces ({}). It is a collection of JSONElement objects. Object members consist if string and values separated by colon in JSON notation.
  • JSONArray : Represents a javascript array that begin and end with braces and contain values. In the notation values are separated by commas, but the library does all the syntactic issues.
  • JSONCollection : A base type for JSONObject and JSONArray.
  • JSONElement : Base class for all JSON types. It has the base properties and can be used with arrays or objects or individually.
  • JSONString : Represents JavaScript string type and created by double quotes. It is inherited from a JSONElement
  • JSONBoolean : Represents JavaScript boolean type
  • JSONNumber<T> : Represents a javascript number type, it can be integer, or floating point numbers.

JSON Tools for .NET is the library that helps to build JSON objects from .NET Framework objects. I just wanted to share the code that I was working previously. It is not a complete library. There is a need for some helper classes for working with dynamic objects and collections. JSONReflector might be useful as a new feature.

You can download the JSON Tools for .NET and play with it. Also, you are very welcome to join and contribute to the project.

A simple example of JSON output looks like this:

{ 
"Total" : 45500, 
"Offset" : 0, 
"Result_List" : [ 
   { "Description" : "JSON (JavaScript Object Notation) (Pronounced like Jason, IPA /d?e?s?n/ ) is a lightweight computer data interchange format. It is a text-based, human-readable format for ... ", 
     "Title" : "JSON - Wikipedia, the free encyclopedia", 
     "URL" : "http://en.wikipedia.org/wiki/Json" } , 
 
   { "Description" : "object {} { members } members pair pair , members pair string : value array [] [ elements ] elements value value , elements value string number object array true false null", 
     "Title" : "JSON", 
     "URL" : "http://www.json.org/" } , 
 
] }

This example is the one of the outputs from the sample directory. It is actually a live search query displayed in JSON string.

In C#, each object is contracted with an IJSONObject interface. That interface has a single WriteObject Method that does the JavScript representation of the actual object.

Here is a sample implementation for a result type object.

public JSONObject WriteObject()
{   
    JSONNumber<int> jTotal = new JSONNumber<int>("Total", m_Total);
    JSONNumber<int> jOffset = new JSONNumber<int>("Offset", m_Offset); 
 
    List<JSONObject> ResultObjects = new List<JSONObject>(m_Results.Count);
    foreach (SearchResult r in m_Results)
    {
        ResultObjects.Add(r.WriteObject());
    } 
 
    JSONArray jResults = new JSONArray("Result_List", ResultObjects); 
 
    JSONObject js = new JSONObject("LiveResults", jTotal, jOffset, jResults);
    return js;
}

Another representation of a result by using different JSON types.

public JSONObject WriteObject()
       {    
           JSONString jDescription = new JSONString("Description", m_Description);
           JSONString jTitle = new JSONString("Title", m_Title);
           JSONString jURL= new JSONString("URL", m_URL); 
 
           JSONObject js = new JSONObject("Result", jDescription, jTitle, jURL);
           return js;
       }

I liked the way it creates JSON object out of an object. No reflection, no dynamic code emit, which means it should have no problems for busy heavy servers.  On the other hand a JSONReflector and a JSONParser could be implemented using the same class library.

Silverlight and DLR

SilverlightBack to my previous post, WPF/Everywhere recently become Silverlight with the addition of new languages and new platform. Actually it’s not a new platform it’s a subset of IronPhyton programming language and it’s called DLR Dynamic Language Runtime. So more to .NET static typed languages, we have some new dynamic languages to be used for scripting in Silverlight. Moreover they will support IronPhyton, IronRuby, JavaScript and VB as dynamic language. It is still possible to use the Silverlight to code using the class library.

I think this is a different move and strategy from Microsoft to target more platforms with completely new and immature languages. However it is very promising in terms of technology it provides, cross platform cross browser flash like environment for different programming languages. We had .NET in different platforms like ASP.NET in the web server, Windows Forms and WPF in Windows and now we have .NET in the browser. You don’t have to have .NET framework to be installed because it comes with a small subset of .NET Framework in the plug-in.

So what it adds more browsing experience is of course the usage of .NET languages and a subset of .NET framework. It means that we can write multithreaded Javascript or C# in the browser plug-in. Different than server client model, the application executes in the client and uses their resources. The silverlight plug-in watches for user interaction and a call-back is being sent to the plug-in or to the browser. JavaScript serialisation, JASON, and marshalizing stuff are handled by Silverlight as well. It allows using asp.net style declarative programming, LINQ and WPF in the browser.

The platforms officially supported are Mac and Windows of course. In a very early stage (in 2 weeks after release) Mono has been released their implementation of Silverlight called Moonlight. This was quick because of the open source and BSD style license of Silverlight. So it is becoming a real cross platform in that case, just like flash does with more programming languages and techniques.

Silverlight is very good at advertising as well. A new developer platform space for sharing Silverlight projects is open, PopFly. It is the area to put silverlight applications and see what is possible with Silverlight. Moreover it is also possible to get 4GB free hosting space from Microsoft Silverlight Streaming. However we don’t know how much they will charge later on.

Silverlight might compete with flash in very short time. Flash is de facto standard for most of the browsers.A lot of web applications run flash to provide rich client features, now Silverlight come to the area with the power of .NET framework and your favourite languages.

Microsoft AJAX 1.0 RTM

It has been more than a year since Atlas is out. I remember playing with the first hands-on-labs for doing a search query. I also really liked the Ajax Control Toolkit since the first day, still using two controls in a project. Now that baby is out of CTP, BETA and ASP.NET AJAX 1.0 is released. A lot has changed since it’s first release. The objects in javascript library, the method names, object names and the product name have changed. As a result, we have 2 separate products. ASP.NET 2.0 AJAX Extensions 1.0 (Client and Server), ASP.NET AJAX Control Toolkit . There is one more product which is ASP.NET AJAX Futures January CTP. This is the additional javascript library to provide additional functionality.

Interestingly, it has been shipped with source code.  There is no escape for the client source code release but they also include the server side controls which is good. Although we don’t have the server side controls code, Scott Guthrie announced the server side controls source code will  be released shortly. Client side is released with Microsoft Permissive License (Ms-PL) and server side with Microsoft Reference License (Ms-RL) The client side is more flexible in terms of license to extend the library.  

Thanks to the team…

WebDD - conference in Reading for web developers and web designers - Registration is Open

WebDD , a free confence in Reading for web developers and web designers, registration is open. It is organized by community and hosted by Microsoft. It is on Saturday 3rd February 2007 at Microsoft Reading, UK. Scott Guthrie will be there. You can find the speakers list and sessions.

There will be also a Geek Dinner like previous DDD events. The registration for the dinner is wiki style as previously. I will be there as well.

See you there.

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

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