Tuesday, September 30, 2008

Visual Studio 2010 and .NET Framework 4.0 announced

Microsoft have provided the first look at the next version of its developer tools and platform, which will be named Visual Studio 2010 and the .NET Framework 4.0. Microsoft described the next release through the following five focus areas: riding the next-generation platform wave, inspiring developer delight, powering breakthrough departmental applications, enabling emerging trends such as cloud computing, and democratizing application life-cycle management (ALM).

Press Release

Tuesday, September 23, 2008

MVC-Model View Controller Pattern for ASP.NET

Model view controller is nothing but a design pattern used to achieve customizability in our application. Change is the only thing in the world, which will never change. All the products that we develop to our clients will undergo many changes. To accommodate these changes we should concentrate more on our design.

Good Layering Approach


MVC follows the most common approach of Layering. Layering is nothing but a logical split up of our code in to functions in different classes. This approach is well known and most accepted approach. The main advantage in this approach is re-usability of code. Good example of layering approach is UI, Business Logic, and Data Access layer. Now we need to think how we can extend this approach to give us another great advantage customizability. The answer to this is using Inheritance. Inheritance is one of the powerful concepts in oops. .Net supports this in a nice way.


View Layer


Our View /UI layer should only have UI related validations in it. We should not have any Business Logic in to it. This gives us the flexibility to change the UI at any time and we can also have different UI for different customers. We can even have web based UI for some of the clients.


Controller /Director


Controller is the layer, which responds to the events in the UI. For example Save button click on my employee master screen. This layer should act as an intermediate between our View and Model. Initially we may think that this layer is not necessary. I am also not convinced with this layer. But still we need to think. May be after some days we will get answer for this. This layer will act as just event redirector.


Model


This layer has all our business logic. This is the most important layer. This layer will have our core functionality. This layer should be designed in such a way that out core and complex logic should be designed as functions and these function should be marked as overridable so that the inheriting classes can re-use the logic or override the logic. We should not make all the functions in the layer as overridable this may raise some security threats. All the database operations should be done in the Model base class. All the inheriting classes should call this method to do database updates.


The Model-View-Controller and Model-View-Presenter Patterns


An example - Class view

Visual Studio 2008 -MVC- Template view





The ASP.NET MVC pattern interms of code is dramatically changed. Now, if we have Visual Studio.net 2008, the MVC project template is bundled with the software. For express editions we can download the templates [you must have Express editions with SP1] from Microsoft site. For more details http://www.asp.net/learn/mvc-videos/

How to run inline code in SharePoint aspx pages

How to run inline code in SharePoint aspx pages
"An error occurred during the processing of test.aspx. Code blocks are not allowed in this file".To enable this you need to modify the web.config file for your SharePoint Site Collection.Modify the web.config file

1. Open the web.config file and make the following change:


The PageParserPaths xml tags will be there already you just need to add the line in between.
2. Save web.config .

How to hide the New! icon in Sharepoint

How to hide the New! icon or control how long the icon is displayed.
The New! icon displays for 2 days by default, but you can use the command line to set that:

[C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN]\stsadm.exe -o setproperty -propertyname days-to-show-new-icon -propertyvalue [Days to Display] -url [Your Virtual Server's URL]

where SharePoint documents are stored ?

where SharePoint documents are stored ?
Exactly where SharePoint stores documents? This is not going to be some thing new for the developlers/ admin’s who used SharePoint for a while, but if you are relatively new to SharePoint it might be somewhat dazzling.
Every time you hit "Save" on a Microsoft Office document and the path for the save is a SharePoint document library on a SharePoint site, the entire contents of the document is saved in binary format in a single image-type field in the SharePoint database. That's right, the entire document, up to 2 GB in size, is stuffed completely into a single field in the SQL Server database that SharePoint uses.
For more details visit
http://msdn.microsoft.com/en-us/library/ms998690.aspx

SharePoint Server and Site Architecture Overview

SharePoint Server and Site Architecture Overview
Microsoft® Windows® SharePoint™ Services offers a highly structured server-side object model that makes it easy to access objects representing the various aspects of a SharePoint site. From higher level objects, you can drill down through the object hierarchy to obtain the object that contains the members you need to use in your code.
Depending on which part of a Windows SharePoint Services deployment that you need to customize, and the type of custom application you are creating, you can use different means of entry into the object model to obtain the appropriate higher-level object from which to start. The SPGlobalAdmin class provides access to the highest levels in the hierarchy, which are related to administrative operations, and you can also use this class to reach the lower objects in the hierarchy. Use the constructor of this class to attain an SPGlobalAdmin object to customize global administrative settings in the deployment.
If you are creating a Web Part, Web service, or Web application to work with site collections, individual sites, or lists, use the GetContextSite or GetContextWeb method of the SPControl class to attain the current site collection or site. When you create a Web application in the _layouts directory, its functionality becomes available to all sites on the Web server. Outside an HTTP context, such as in a console application, use the constructor of the SPSite class to attain a specified site collection.The following diagram shows the Windows SharePoint Services site architecture in relation to the collections and objects of the Microsoft.SharePoint and osoft.SharePoint.Administration namespaces.







1 The ContentDatabases property of the SPVirtualServer class returns an SPContentDatabaseCollection object that represents the collection of content databases used for a virtual server. Each SPContentDatabase object provides access to properties of the content database.
2 The WebServers property of the SPGlobalConfig class returns an SPWebServerCollection object representing the collection of front-end Web servers in the Windows SharePoint Services deployment. Each SPWebServer object provides access to properties of the Web server.
3 The VirtualServers property of the SPGlobalAdmin class provides access to an SPVirtualServerCollection object representing all of the virtual servers in the Windows SharePoint Services deployment. The OpenVirtualServer method of the SPGlobalAdmin class returns a specific virtual server. Each SPVirtualServer object has members that can be used to manage the virtual server. The Sites property provides access to the SPSiteCollection object representing the collection of all site collections on the virtual server, and the Add method is used to create top-level site collections.
4 Each SPSite object represents a site collection and has members that can be used to manage the site collection. The AllWebs property provides access to the SPWebCollection object that represents the collection of all sites within the site collection, including the top-level site. The OpenWeb method of the SPSite class returns a specified site.
5 Each site collection includes any number of SPWeb objects, and each object has members that can be used to manage a site, including its template and theme, but also to access files and folders on the site. The Webs property returns an SPWebCollection object representing all the subsites of a specified site, and the Lists property returns an SPListCollection object representing all the lists in the site.
6 Each SPList object has members for managing the list or for accessing items in the list. The GetItems method can be used to perform queries that return specific items. The Fields property returns an SPFieldCollection object representing all the fields, or columns, in the list, and the Items property returns an SPListItemCollection object representing all the items, or rows, in the list.
7 Each SPField object has members that contain settings for the field.
8 Each SPListItem object represents a single row in the list.




For more details vist

http://msdn.microsoft.com/en-us/library/aa151977.aspx

Read large text files using C#

Read large text files using C#

Reading and manipulating all the individual lines of a text file in a For Each loop isn't difficult. For example you can load all the text lines in a string array, use the array in a loop, as following
using System.IO;

using System.Text.RegularExpressions;
StreamReader sr = new StreamReader(@"c:\test.txt");
string[] tempArr = Regex.Split(sr.ReadToEnd(), @"\r\n");
// don’t forger to do house keeping for stream object using try - finally
sr.Close();
foreach ( string str in tempArr)
Console.WriteLine(str);
This approach does not work in the case of large files. Because, the above code reads all the contents into the memory. For lager files (say 20MB or higher,) the program may crash or intensively slow depends on your processor / RAM speed. We can solve this memory problem and still use the For Each loop by creating our custom class TextFileReader class that implements the dotnet’s IEnumerable interface. The interface has only one method GetEnumerator, which is expected to return an instance of another class, which must implement the IEnumerator interface.

In dotnet 2.0 we can use IEnumerable interface
using System;

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
public class TextFileReader : IEnumerable, IDisposable
{ // The StreamReader object
StreamReader sr;
public TextFileReader(string path)
{ sr = new StreamReader(path); }
public void Dispose()
{ // close the file stream
if (sr != null)
{ sr.Close(); }
}
// the IEnumerable interface
public IEnumerator GetEnumerator()
{
while ( sr.Peek() != -1 )
{
yield return sr.ReadLine();
// The "yield" keyword is used to iterate through objects returned by a method.

It creates a state engine in IL so we can create methods that retain their state and we no need to

maintain the state in code.
}

Dispose();
}
IEnumerator IEnumerable.GetEnumerator()
{ return GetEnumerator(); }
}
We can use the TextFileReader object as followes.
TextFileReader TFR = new TextFileReader(@"c:\test.txt");

foreach (string str in TFR)
Console.WriteLine(str);
Happy coding.

-Rajesh Pillai