Thursday, January 15, 2015

Creating a SharePoint solution without any tool WSP Builder and VS2010. (Learning Basics)

To deploy anything into SharePoint you need below given three files :

1. Manifest.xml - Data about your solution structure.
2. ddf - Data 
3. dll - 

These are the files we need to deal with while deploying a solution in SharePoint. However now a days we have all these file creation and deployment would be done by Visual Studio or WSP builder.
These are aweesome tools and are very efficient, But as a Sharepoint Developer we still need to learn what happens behind the scene, files and its roles.

1. dll file - Just rebuild your solution and open BIN folder of your solution. Copy this dll file and copy it to the deployment folder of your application. Copy this DLL file into GAC and get details of public key token.

2, Manifest,xml -  Just add this file into Deployment folder. And provide all details as per your solution. 
SolutionId - Create a new GuId in registry format and add it.
PublicKeyToken - Details of your dll from GAC.

<?xml version="1.0" encoding="utf-8" ?>
<Solution xmlns=""
 SolutionId="{04B8CC83-70A0-49cb-A745-91A89437A93F}" >

    <Assembly DeploymentTarget="GlobalAssemblyCache" Location="TestByKrishna.dll">
        <SafeControl Assembly="TestByKrishna, Version=, Culture=neutral, PublicKeyToken=1723b722c17f1304" Namespace="TestByKrishna" TypeName="*" Safe="True" />


3. ddf file - This file will be used as an input file for running makecab.exe utility. Just replace the dll file name and name of the WSP you want.

; makecab.exe tool takes a pointer to a .ddf file, 
;which describes the structure of the .cab file.  
;The This file is for WSP CAB Generation
;A WSS or in this case MOSS solution file is essentially a .cab file, 
;use the makecab.exe tool to create the solution package. 
;Theformat of a .ddf file is basically that
;you declare a standard header and 
;then enumerate, one file per line, the set of files by where they live on disk, 
;separated by where they should live in the .cab file

.OPTION EXPLICIT     ; Generate errors 
.Set CabinetNameTemplate="TestByKrishna.wsp"
.set DiskDirectoryTemplate=CDROM ; All cabinets go in a single directory
.Set CompressionType=MSZIP;** All files are compressed in cabinet files
.Set UniqueFiles="ON"
.Set Cabinet=on
.Set DiskDirectory1="Package"
;All file reference should be from the project root
;Files to place into the CAB Root

; Manifest


Now run the following command from by cmd by pointing to the Deployment folder of your solution. Which contains these three files. 

You can see WSP in the package folder of your solution as per below image :

Now you can deploy your WSP on any server using Stsadm or powershell or Central Admin.

Tuesday, January 13, 2015

Get all duplicate values from a data table for a particular column.

Here is a method which I have created to get all the rows which have duplicate values for title column. Code is as below :

protected DataTable FormatDataTableForClientDICBIC(DataTable objDatatable)
            DataTable dt = new DataTable();
// Below content in bold format will help us to find all the Title which are present more than once in list with all number of occurences.
            var duplicates = objDatatable.AsEnumerable()
            .Select(dr => dr.Field<string>("Title"))
            .GroupBy(x => x)
            .SelectMany(grp => grp.Skip(1));

            if (duplicates.Count() > 0)
                DataTable dtTitle = new DataTable();
                foreach (var item in duplicates)
                    DataRow dr = dtTitle.NewRow();
                    dr["Title"] = Convert.ToString(item);

// Gets distinct values from each of them.

                DataView view = new DataView(dtTitle);
                DataTable distinctValues = view.ToTable(true, "Title");

                //List<DataRow> rows = new List<DataRow>();
                foreach (DataRow item in distinctValues.Rows)
                    string ICName = Convert.ToString(item["Title"]);
                    //DataRow dr = dt.NewRow();
                    //dr["IC Name"] = ICName;

                    if (!string.IsNullOrEmpty(ICName) && (!(ICName.Equals("TBD") || ICName.Equals(@"N/A") || ICName.Equals("Declined"))))
                        var dataResults = from r in objDatatable.AsEnumerable()
                                          where (Convert.ToString(r["Title"]) == ICName)
                                          select r;
                        if (dataResults.Count() > 0)
                            foreach (var subitems in dataResults)
                                DataRow dr = dt.NewRow();
                                dr["Column1"] = subitems["Column1"];
                                dr["Column2"] = subitems["Column2"];
                                dr["Column3"] = subitems["Column3"];
                                dr["Column4"] = subitems["Column4"];
                                dr["Column5"] = subitems["Column5"];
                                dr[""Column6] = subitems["Column6"];
                                dr["Title"] = subitems["Title"];


            return dt;


Now we can use this returned data table to show all repeated titles with details of all columns. If you want you can also use the schema of Same DataTable which is an input parameter, instead of writing a new one. Hope it helps. Please let me know if there is any better way (performance wise) to do it.