Showing posts with label VS 2005. Show all posts
Showing posts with label VS 2005. Show all posts

Monday, January 4, 2010

Content migration from documents to wiki (MediaWiki)

This article will cover following topics
• Statement of problem
• Feasible solutions to achieve the goal
• Automating conversion of documents using VBA macros
       o What are VBA macros
       o Functional details
• Technical aspects
       o Technology used
       o Class details
       o IO/user interface
• Configuration
       o How to use the application
       o Extend the application to web or windows
       o Exception
       o Limitation and support
Statement of problem:
To convert documents (doc/pdf/excel) to wiki formatted text so that it can be directly hosted on a wiki server and a mass import of content or document import to wiki can be achieved.
Feasible solutions to achieve the goal: The following two approaches can be followed to achieve the solution.
• Automating conversion of the documents in wiki text, using VBA macros (preferred)
• Reading the entire content with inline formatting and applying wiki syntax to it.
Automating conversion of documents using VBA macros:
• What are VBA macros: Macros are Code written in VBA ,is compiled[ to a proprietary intermediate language called P-code (packed code), which is stored by the hosting applications (Access, Excel, Word) as a separate stream in Structured storage files (e.g. doc or xls) independent of the document streams. The intermediate code is then interpreted.
• Functional details: following steps are mentioned below:
     o Write a macro for each document type as excel, word or ppt which can convert the content in wiki format by persisting the data/formatting and save the output temporarily in the same file
     o Save the macro in .bas format (change/set the extension to .bas)
     o Automate the office documents using .net libraries which can attach the corresponding macro to the document and execute the macro on the documents.
     o Read the output (wiki formatted text) generated by macro and publish it to the hosted wiki using the Mediawiki API’s for .net

Technical aspects:


• Technology used: Asp.net, VBA Macros, PHP, Media Wiki, IIS, apache web server
       o write macro for each excel and word documents to convert in wiki formatted text
       o create .net based class library to convert PDF to word document
       o create .net based class library to automate the office application which can add and execute the macro
• Class details: project contains a class library (wikiconversion) to automate the document conversion, media wiki API’s (wikiaccess) and a console program to invoke the application


• IO/user interface: the project includes a console application by which the application can be simulated, hence there is no visible UI design. It takes input from the folder Documents read all documents in the folder and hosts the doc and excel type in media wiki. An output file is generated in the Output folder under Documents with the current timestamp with the status of documents processed. (Same library can be extended for any web or window application as needed)


Configuration: Following configuration required to run the application

1. A Mediawiki hosted on apache server (mediawiki should support the call From API e.g. $wgEnableAPI=true in localSettings.php file)
2. All the documents that has to be converted must be in documents folder of the application
3. Macros folder which consist macros for word and excel file, should be in the application with relevant word and excel macros. For further details on macro please follow this link http://en.wikipedia.org/wiki/Visual_Basic_for_Applications
4. Wikiconversion.config must be updated with relevant config values like mediawiki server name and various files path

o How to use the application: set the configuration values in config file appropriately, place the file to be converted in documents folder and run the content import project

o Extend the application to web or windows: Create a web or window application, and call the various functions available in wikiconversion class (refer the code written in Main function for more details)

o Exception: Any corrupted file or very big file in size might take either too long to host on wiki or fail to do so. Accuracy of Conversion from documents to wiki depends on the macros placed in application Macro can be replaced for better output as further if available. Current macros convert the most of features/format appropriately still some issues can be there in word macro.

o Limitation and support: currently application support only MS-Word and MS-Excel file to convert and host in media wiki but the same can be extended to PDF,HTML,PPT by converting them to MS-word documents.URL generated in output file might mislead sometimes

References: http://www.mediawiki.org/wiki/API

Introduction to Web Parts in ASP.NET/MOSS 2007

Content:

• Introduction
• System requirement
• Web part framework
• Comparing with asp.net
• Creating a new web part solution
• Deploying and debugging



Introduction:

Microsoft ASP.NET 2.0 provides a Web Part infrastructure that helps you build custom Web Parts and deploy them to Web sites built using Microsoft Windows SharePoint Services 3.0. This article provides a walkthrough how to build custom Web Parts that work in both standard ASP.NET 2.0 Web sites and Windows SharePoint Services 3.0.



Web part framework:

A Web Part is an ASP.NET server control designed to be edited and modified by users in the browser. It works as a component of a SharePoint site that presents information pulled from multiple data sources. Web Part pages allows to personalize information relevant to the needs by updating the value of specific Web Part properties. SharePoint Web Parts are UI elements that support both customization and personalization.

The Web Part infrastructure in Microsoft Windows SharePoint Services 2.0 and Microsoft Office SharePoint Portal Server 2003 provides a framework to build custom Web Parts targeted to Microsoft SharePoint Products and Technologies by using managed code.

ASP.NET 2.0 includes a new Web Part control set that allows site customization and personalization on custom Web sites that are independent of MOSS. The Web Part infrastructure in Windows SharePoint Services 3.0 exists on a layer above the ASP.NET 2.0 Web Part infrastructure.






Comparing with asp.net:


Office SharePoint Server 2007 and Windows SharePoint Services 3.0 are built on top of the ASP.NET 2.0 Framework. Windows SharePoint Services 3.0 uses the ASP.NET 2.0 Web Part infrastructure to take advantage of features such as master pages and custom Web Part development while providing a complete set of Windows SharePoint Services features, such as document services, events, workflow, search, site columns, content types and more.

We can build Web Parts for Windows SharePoint Services 3.0 in two ways:

• Create custom ASP.NET 2.0 Web Parts.
• Create SharePoint-based Web Parts.

The following table provides a decision matrix to help you choose the best option depending on your business needs.


Creating a new web part solution:
 
To create a new Web Part solution
o Open VS 2005 > File menu> click New, and then select Project.
o In Project types, select Visual C#, and then select SharePoint.


o In Templates, select Web Part.


o Specify a new name, location, or solution name of Web Part, and then click OK. The extensions create a new Web Part solution project, which includes the following:

 References to the Microsoft.sharepoint

 AssemblyInfo.cs, a file that enables you to specify company and product information for the Web Part assembly, and version information

 Temporary.snk, a temporary signature key file for the Web Part assembly

 A Visual C# code file for the Web Part, named the same as the Web Part name

 By default, the code file for the Web Part contains the following:

 using statements for the necessary System and Windows SharePoint Services namespaces, such as Microsoft. SharePoint, Microsoft.SharePoint.WebControls, and Microsoft.SharePoint.WebPartPages

 An empty Web Part class that inherits from System.Web.UI.WebControls.WebParts.WebPart

o Add the code you want to the Web Part class.



Customizing the Web Part Solution Package


The Web Part project template automatically generates the XML files needed to package your Web Part as a MOSS 2007 feature for deployment and activation. The required GUIDs contained in the XML files are also generated automatically.

The extensions generate a .webpart file as the element.xml file for the Feature containing the Web Part. Every Web Part should have a .webpart file, which is an XML file that describes the Web Part. The .webpart file also makes your Web Part appear in the Web Part gallery in MOSS 2007.

we can customize the information in these XML files by editing solution, Feature, and element properties on the SharePoint Solution tab in project's Properties dialog box, as follows:



o Solution Information in this node is written into the manifest.xml file for the Feature. You can set the following solution property:

o Name The name of your Web Part solution.

o Feature Information in this node is written into the feature.xml file for the Feature. You can set the following feature properties:

o Folder Name The name of the folder to contain the files for this Feature.

o Title The title of the Feature. Limited to 255 characters.

o Description A longer representation of what the Feature does.

o Version Specifies a System.Version-compliant representation of the version of a Feature. This can be up to four numbers delimited by decimals that represent a version.

o Scope The Feature scope. Can contain one of the following values: Farm (farm), WebApplication (Web application), Site (site collection), or Web (Web site).

o Hidden Hides the feature. This attribute is FALSE by default.

o Default Resource File Indicates a common resource file for retrieving Feature XML resources.

o Element Information in this node is written into the element.xml file for the Feature. As mentioned earlier, this file contains the information usually contained in a .webpart file. You can set the following element properties:

o Title The title of your Web Part on web page.

o Description The description of your Web Part that you want to appear in the Windows SharePoint Services user interface.

o ImportErrorMessage The error string to display if Windows SharePoint Services is unable to import your Web Part solution.


Customizing the Web Part solution feature package


o In Solution Explorer, right-click the Web Part project, and then select Properties.

o In the Properties window, select SharePoint Solution. This tab lists the nodes that contain the properties for the solution package that the extensions will generate.

o Expand the Solution node, and then expand the Feature node and the Element node.

o To edit properties for a node, click a node, and then edit the properties. For example, click the Element node, and then edit the values for the Title, Description, and ImportErrorMessage keys.

o To commit your changes for a node, click in the Description value field.




Deploying and debugging:

We can deploy and start debugging of the Web Part simply by pressing F5.

When you press F5, the extensions automatically build, deploy, and initiate debugging of Web Part solution Feature. To accomplish this, the extensions perform the following actions automatically:

o Build the Web Part assembly.

o Package the Web Part solution as a Windows SharePoint Services Feature.

o If this Web Part solution was deployed previously, the extensions retract the previous version of the Web Part solution Feature.

o Install your Web Part assembly to the global assembly cache using gacutil utility

o Deploy and activate your Web Part solution Feature in Windows SharePoint Services.

o Add your Web Part to the Safe Controls list.

o Restart Microsoft Internet Information Services (IIS) by invoking the iisreset command.

o Attach to the w3wp processes to enable debugging.


Thursday, October 16, 2008

Introduction to Nullable types in C# 2.0

Content:
• Introduction
• System requirement
• Nullable type’s use
• Creating Nullable types
• The ?? Operator
• Sending Nullable types to the Database
• Nullable objects and the relational and logical operators
Introduction:
Prior to C# 2.0 there was an inability to assign a null value to certain types e.g. Int, DateTime, Float, Decimal. Microsoft C# 2.0 provides nullable type that allows you to assign a null to "value types" that have previously not allowed such an assignment. This article provides a walkthrough how to use nullable types in c# and working of ?? Operator with nullable types.


System requirement
The following software required to be installed
• .net framework & Visual studio 2005

Nullable type’s Use:
Databases use null as being distinct from values such as 0 and false. Without nullable types, mapping of c# data type to database null field depends on arbitrary decision taken by user. In different situations a null in a Boolean field may be equivalent to false or it may be equally valid to map it to true. Nullable types overcome this problem and allow any database value - including the “no value” of null - to be mapped directly to value types in C#. Databases are not the only example either. Any situation where something may not be defined, and only has a meaningful value if it is defined is benefit of nullable types. Optional parameters in XML or HTML also can be set equivalent to null which was not directly possible earlier. Likewise the square root of -1 in real number scenarios, the age of a customer who declined to say how old they are, or the time to completion of some batch process that’s not yet started are some perfect uses of nullable types. So Nullable types can save development time and ease program maintenance. In the past, handling the possibility of unused fields required the use of either placeholder values but this could only work if there was a value that would otherwise be invalid or an extra field that simply indicated whether a field was in use, but having to manually create and manage such a field is annoyance. The nullable type solves both the problems.

Creating Nullable types:
A nullable type is a special version of a value type that is represented by a structure. Nullable types are objects of System. Nullable, where T must be a non nullable type. Nullabe types can be declared in two different ways. First it can be explicitly declared as object of System.Nullable. For example, this creates int and bool nullable types –

System.Nullable intCount;
System.Nullable boolDone;


Secondly it can be declared using short hand method as follows:

int? intCount;
bool? boolDone;


There are two ways to determine if a variable of nullable type is null or contains a value. Nullable variable can be compared with null value or HasValue read-only property can be used.

int? intCount = null;
if (intCount != null )
Console.WriteLine(intCount);
if (intCount.HasValue)
Console.WriteLine(intCount);

If a nullable variable is null and its value is tried to obtain then System.InvalidOperationException will be thrown. Nullable variable’s value can be obtained by using the Value read-only property or by casting it into its underlying type.
Following code sample demonstrates this:-

using System;
using System.Collections.Generic;
using System.Text;

namespace NullableTypeBOK
{
class NullableType
{
static void Main(string[] args)
{
int? intCount = null;
if (intCount.HasValue)
Console.WriteLine(intCount.Value);
else
Console.WriteLine("Count has no value");

intCount = 100;
if (intCount.HasValue)
Console.WriteLine(intCount.Value);
else
Console.WriteLine("Count has no value");

Console.Read();

}
}
}


A nullable object can be used in expressions in the same way as its underlying type. When non-nullable and nullable types are mixed in an operation, the outcome is a nullable value.

The ?? Operator:
The ?? Operator is also called the null coalescing operator, which lets us specify a default value that will be used when nullable object contains null. If without using ?? Operator nullable object is tried to cast to its underlying type then System.InvalidOperationException will be thrown if the nullable object contains a null value. It can be declared as follows:-

Nullable-object ?? Default-value
If nullable object contains a value, then the value of ?? Operator is that value. Otherwise the value of the ?? Operator is default value. For example, in the following code amount is null. This causes Interest to be assigned the value 0.0 and no exception will be thrown and if amount is set to some value then interest will be accordingly.
static void Main(string[] args)
{
float Interest;
System.Nullable pAmount = null;
// if pAmount=10.0F then Interest=40 otherwise 0
System.Nullable rate = 0.8F;
System.Nullable time = 5;
Interest = (pAmount * rate * time) ?? 0.0F;
Console.WriteLine(Interest);
Console.Read();
}

The right hand expression of ?? Operator is evaluated only if left hand side of the operator does not contain a value.

Sending Nullable types to the Database:
Nullable types can be sent to the database and have DBNull inserted for types that have a null value. To do this the ??Operator is used and DBNull is casted to an object. The cast is required because the objects on either side of the ??Operator must be compatible.

Nullable objects and the relational and logical operators:
Nullable objects can be used in relational expressions as same as their corresponding Non-Nullable types. However, when two nullable objects are compared using the <, >, <= or >= operators, the result is false if either of the object is null.
When a logical expression involves two bool? Objects, outcome will be true, false or null. Following truth table shows the entries for the & and operators that apply to bool?.



References:
http://www.blogger.com/www.msdn.com
http://www.blogger.com/www.techrepublic.com