using System.Collections; using System.IO; using System.Xml; using System.Xml.Serialization; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { AListWrapper wrapper = new AListWrapper(); XmlSerializer mySerializer = new XmlSerializer(typeof(AListWrapper)); StreamWriter myWriter = new StreamWriter("c:\\myFileName.xml"); mySerializer.Serialize(myWriter, wrapper); myWriter.Close(); } } public class Animal { public string Type { get; set; } public int Age { get; set; } } public class Employee { public string Name { get; set; } public double Salary { get; set; } public string Address { get; set; } } [XmlRoot("ArrayList")] public class AListWrapper { [XmlElement(Type = typeof(Employee)), XmlElement(Type = typeof(Animal))] public ArrayList list = new ArrayList(); public AListWrapper() { Animal animal = new Animal() { Age = 1, Type = "Dog" }; Employee emp = new Employee() { Address = "Address", Name = "SomeName", Salary = 2000.50 }; list.Add(animal); list.Add(emp); } } }
Wednesday, May 18, 2011
Serialize Multiobject ArrayList to XML
Wednesday, May 4, 2011
jQuery 1.6 Released
jQuery 1.6 is now available for download!
jQuery CDN:
Microsoft Ajax CDN:
You can read more about this on the following link: http://blog.jquery.com/2011/05/03/jquery-16-released/
Monday, May 2, 2011
SharePoint 2010 Word Automation Services
In SharePoint 2010, you can add "Word Automation Services" from Central Admin as shown below
Once the service is in place, we can easily convert Word documents to PDF as shown in below snippet
private voidConvertDocFileToPDF(SPFile filex)
{
ConversionJobSettings settings = newConversionJobSettings();
settings.OutputFormat = SaveFormat.PDF;
ConversionJob job = newConversionJob(ConfigurationHelper.Instance.DocumentConversionService, settings);
job.UserToken = SPUserToken.SystemAccount;
stringpdfFile = filex.Url.Replace("docx", "pdf");
job.AddFile("http://<your site URL>/"+ filex.Url, "http://<your site URL>/"+ pdfFile);
job.Start();
}
Ensure to add reference to “Microsoft.Office.Word.Server” present under 14 hive “ISAPI” folder.
To test this, run “Word Automation Services Timer Job”
DataTable to GenericList | C# and LINQ

using System; using System.Data; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { DataTable table = new DataTable { Columns = { {"Id", typeof(int)}, {"Name", typeof(string)} } }; table.Rows.Add(1, "Amal"); table.Rows.Add(1, "Fousiya"); table.Rows.Add(1, "Munna"); table.Rows.Add(1, "Hussain"); var listOfEmployees = from row in table.AsEnumerable() select new Employee { Id = row.Field<int>("Id"), Name = row.Field<String>("Name") }; foreach (Employee emp in listOfEmployees) { Console.WriteLine("{0} {1}", emp.Id, emp.Name); } } } class Employee { public int Id { get; set; } public String Name { get; set; } } }
Friday, April 1, 2011
MVP 2011 - For the second time
Today I got awarded as MVP for the second time in a row. See the mail i got...feeling really happy.
From: support@mvpaward.com
To: amal.hashim@hotmail.com
CC: abhishek@microsoft.com
Date: Fri, 1 Apr 2011 09:12:39 -0500
Subject: Congratulations 2011 Microsoft MVP!
Dear Amal Hashim,
Congratulations! We are pleased to present you with the 2011 Microsoft® MVP Award! This award is given to exceptional technical community leaders who actively share their high quality, real world expertise with others. We appreciate your outstanding contributions in Visual C# technical communities during the past year.
Also in this email:
- About your MVP Award Gift
- How to access www.mvpaward.com to begin taking advantage of your award benefits
- Your MVP Identification Number
- MVP Award Program Code of Conduct
Toby Richards
General Manager
Community & Online Support
Monday, January 24, 2011
Color Coding SharePoint List – With or Without Grouping
Using jQuery we can easily color code lists in SharePoint 2007.
Try using the following script
<script type="text/javascript" src="/_layouts/jquery-1.4.4/jquery-1.4.4.min.js"></script>
<style type="text/css">
.MyStyle
{
font-size: 11px;
background-color: red;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
$(".ms-vb2:contains('Completed')").each(function(){
$(this).addClass(MyStyle);
});
});
</script>
Problem with this approach is, it won’t work in views with grouping. The problem is, on grouping, collapsed group data is not rendered on page load. To tackle this we need to tweak scripts in INIT.js, but directly modifying is not a good practice. To overcome this we can override the method which is rendering the data as shown in the below script block.
<style type="text/css">
.MyStyle
{
font-size: 11px;
background-color: red;
}
</style>
<script type="text/javascript" src="/_layouts/jquery-1.4.4/jquery-1.4.4.min.js"></script>
<script type="text/javascript">
//wait until all of the SharePoint stuff is loaded...
_spBodyOnLoadFunctionNames.push("CustomExpGroupByFix");
function CustomExpGroupByFix()
{
//Replace the function in INIT.JS with our custom function
window.ExpGroupReceiveData=function(x,y){ExpGroupReceiveDataC(x,y)}
}
//This is the exact replica of INIT.JS "ExpGroupReceiveData", we have added color coding code at the end
function ExpGroupReceiveDataC(htmlToRender, groupName)
{
var ctxId="ctx"+groupName.substring(0, groupName.indexOf("-"));
var indexBeginCTXName=htmlToRender.indexOf("CTXName=\"");
if (indexBeginCTXName !=-1)
{
if (ctxId !="ctx1")
{
htmlToRender=htmlToRender.replace(/ CTXName=\"ctx1\" /g, " CTXName=\""+ctxId+"\" ");
}
}
var needOuterWrap=false;
if (htmlToRender.length < 4)
{
needOuterWrap=true;
}
else if (htmlToRender.substring(0,3) !="<tr")
{
needOuterWrap=true;
}
if (needOuterWrap)
{
htmlToRender="<TR><TD>"+htmlToRender+"</TD></TR>";
}
ExpGroupRenderData(htmlToRender, groupName, "true");
g_ExpGroupInProgress=false;
if (g_ExpGroupQueue.length > 0)
{
ExpGroupFetchData(g_ExpGroupQueue.shift());
}
//Color coding the cells
$(".ms-vb2:contains('Completed')").each(function(){
$(this).addClass(MyStyle);
});
}
</script>
To use this script, edit the page –> add a content editor webpart.
Friday, October 22, 2010
MOSS | Using WSPBuilder for Creating a List Instance
First we need to install SharePoint Solution Generator. You can download the same from here
http://download.microsoft.com/download/4/0/b/40b62080-6295-4d63-b396-d779fb9b4449/VSeWSSv12.exe
Now follow the steps for generating List Definition. Here I am going to create a List Definition of a List named “Configurations”
Start SharePoint solution generator
Select List Definition and click on Next button
Specify the Site Url where the list is present and click Next
Select the List and click Next
Provide a project name and path, then click Next
Click Finish
Before clicking Exit, click “Click here to open the generated solution” and click Exit
You can see the “Configurations” folder. Let it be opened. Now open visual studio and create a WSPBuilder project
Once the project is created, add a new blank feature
Now, copy the folder “Configurations” and paste it under the feature folder as shown below
Open the ListDefinition.xml file and copy the following content
Once the content is copied, paste it in the elements.xml file as shown below and delete the file "ListDefinition.xml" from visual studion project
You can also see ListInstance, make a similar entry in your elements.xml file. Also replace the FeatureId with the FeatureId specified in the feature.xml file
Now build the wsp, deploy it and activate the feature. This will add the list to the site.
Hope this was helpful!!!
