Wednesday, December 30, 2009

Sharepoint 2010 new things

You can find all this new intersting things of Sharepoint 2010 to offer in Nuts and Bolts of Sharepoing Blog

1) Scalability/list throttling.
2) Enterprise Content Types.
3) User Experience.
4) Content Organizer or Drop-Off Library.
5) Document Sets.
6) Tagging.
7) Taxonomy

Tuesday, December 29, 2009

Xslt with C# scripting

First I would like to discuss on how to insert c# scripting in xslt, which is sometimes very helpful specially when parsing involve, which is quite complicated in xslt code. The 2nd part of is how to render xslt with c# code in c#.

Part 1

1) On the style sheet element add the msxls namespace and c# code namespace, as show below.

<xsl:stylesheet version="1.0" xsl="http://www.w3.org/1999/XSL/Transform" row="http://tempuri.org/NewsLetterData.xsd" msxsl="urn:schemas-microsoft-com:xslt" prefixes="msxsl" code="Code"></xsl:stylesheet>

2) After the xslt element proceed with your c# code script as shown below. Add some assembly and assembly namespace which your code used.

<?xml:namespace prefix = msxsl /><msxsl:script language="C#" prefix="Code">
<msxsl:assembly name="System.Data"></msxsl:assembly>
<msxsl:using namespace="System.Text"></msxsl:using>
<msxsl:using namespace="System.IO"></msxsl:using>
</msxsl:script>


3) When c# code is ready you can easily call your code inside your xslt by specifying <code namespace declared>:<codename>.

<xsl:variable name="output" select="Code:YourCodeHere($parameter)" />

Rendering Xslt with c# code

Enabling XSLT intellisense

To enable some additional Xslt intellisense in Visual Studio run Registry Editor and navigate to My Computer\HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\XmlEditor and locate registry key XsltIntellisense and set its value to "True".

Positive, Negative or Zero number string formatting in c#

The code below shows how to format an integer values with positive, negative or zero values.

int positiveNumber = 1000;
Console.WriteLine(string.Format("{0:$#,###.00;($#,###.00);$0.00}",positiveNumber));

int negativeNumber = -1000;
Console.WriteLine(string.Format("{0:$#,###.00;($#,###.00);$0.00}", negativeNumber));

int zeroNumber = 0;
Console.WriteLine(string.Format("{0:$#,###.00;($#,###.00);$0.00}", zeroNumber));


outputs are:

$1,000.00
($1,000.00)
$0.00

Enum with binary comparison (bitwise AND operation)

Below is an example on how to compare values using binary with enum type.

1) Declare enum variable with specified binary values.

enum status
{
Adding = 0x1, Modifying = 0x2, Deleting = 0x4, Modified = 0x8, Deleted = 0x16
};


2. Create an new instance of enum with explicit values using "|" or a bitwise OR operation.

status newStatus = status.Modified | status.Deleted;

3. Now using binary comparison using bitwise AND operation to check if enum value was included with the new instance created.

bool ifExists = ((newStatus & status.Modifying) == status.Modifying);

The code example above returns false since "Modifying" was not declared in newStatus enum.

Monday, December 28, 2009

Start blogging

This is the day to start blogging. Nice site.