Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand

Archive for December, 2012

SharePoint & SkyDrive

Posted by Jean Paul on December 31, 2012

The trend for SkyDrive usage is coming up as more and more apps are available. Apparently the 25 GB storage was reduced to 7 GB. In this article we can see the advantages of SkyDrive & Possibilities of usage with SharePoint.

What is SkyDrive?

Windows Live SkyDrive (initially Windows Live Folders) is part of Microsoft’s Windows Live range of online services including Cloud Storage to store & sync files. SkyDrive files can be accessed through Browsers & mobile devices. Additional to storing SkyDrive provides Sharing facilities. We can access SkyDrive using URL:




In the technological world, interestingly there will be equivalent stuffs. You can see SkyDrive equivalent to Google Docs, Google Drive & associated synchronizing mechanisms.

What are the advantages of SkyDrive?

The advantages can be summarized as:

· Cloud Storage allows access of files from anywhere

· Good Backup Mechanism

· Free Storage up to 7 GB

· Free Office Web Apps

· Sharing Facility

· Quick Creation of SkyDrive Account

· Large files upload supported

· SkyDrive apps for Synchronizing in Multiple Devices

The advantages are depicted below:


How to create a SkyDrive Account?

This will take just 2 minutes. Believe me!

Open your browser and enter the URL:



In the appearing page you can enter your Microsoft Account & Password, then clicking the Sign in button. If you do not have a Microsoft Account use the Sign up now link to create one.

After logging in you can see the following page. You can use the Upload button to upload files.




Office Web Apps

You can use the Office Web Apps to work with Word / Excel / Power Point / OneNote files without the need of MS Office installed in your computer. You can use the Create menu from the top bar.


On entering the new document name in the dialog appearing, you will be taken to the Word Web App as shown below. Here you can edit & save the document. There are limited access to the original MS Word features.


Similarly you can use the other Office Web Apps like Excel, Power Point etc.

Please note that there is a “Open in ..” command which allows opening the file in Office Application (if installed).

SkyDrive Apps

For synchronizing your files automatically, use the following SkyDrive App.


After installing you will get a new SkyDrive item in the Windows Explorer.


SharePoint & SkyDrive

Now let us see how SharePoint can work with SkyDrive. Following are some of them.

SkyDrive Connector for SharePoint

SkyDrive Connector for SharePoint is a sandbox web part that can help manage documents stored on SkyDrive on SharePoint by adding additional metadata. This helps the document to be discoverable on SharePoint.


You can download it from:

Sharing Files in SkyDrive

We can share files in SharePoint or SkyDrive. Inside the Office Application choose the Share / Save As option to locate the SkyDrive folder.

Some Tips for using SkyDrive

Use 2 SkyDrive Accounts

There are basically 2 kinds of files we need to backup:

· Those are Changed Frequently. They include your Office Documents like Word, Excel, PowerPoint etc.

· Those are NEVER Changed. They include eBooks, Photos, MP3 files, Video clips

Automatic Synchronization is advantageous as you will never end up with a loss of data scenario. In this case you can use one SkyDrive account for automatic synchronizing. The other account can be used for manual uploading & sharing.

Create Free Accounts

If the 7 GB limit is not enough, you are good to create more free SkyDrive accounts.



In this article we have explored the SkyDrive features & SharePoint possibilities to work with it. You can find more tools & resources for SharePoint that works with SkyDrive.

Posted in C#, SharePoint | Tagged: , | Leave a Comment »

Squadron for SharePoint 2010 – Copy Items

Posted by Jean Paul on December 18, 2012

In this article we can explore new feature integration to our Squadron Tool for SharePoint 2010.


Copy Items

The Copy Items functionality is simple as the name implies:

· It copies list items from source server list to destination server list

It helps us in the following ways:

1. Quick Creation of Lists from server to another

2. Duplication of Items if the lists are same

3. Multiple List copying

We can use the tool to copy multiple lists across sites..



Squadron 2010 is a Utility Add in Application for SharePoint 2010. It is available for download from:

The method performs the following:

1. Accepts a Source List Item and Destination List

2. Creates a New List Item inside Destination List

3. Iterates over each Field of the Source Item and copies the property to Destination Item

4. Discards field names of ‘Attachments’

5. Updates the list item on the end of method

Start using the Tool

You can download the tool from above location.

Step 1: Execute the Tool

You will get the following screen on execution.


Step 2: Click Copy Items

Click on the Copy Items item from the left pane and you will see the following add-in.


Step 3: Source Server Connect

As the screen implies, you have to do the following steps of actions:

Step 1: Source Server Connect In this step input the URL of the Source Server. You can enter the user name if needed higher permissions. (By default it is SHAREPOINT\system)

For the time being enter your SharePoint site url here:


Then click the Refresh button. You will get the Lists loaded in the Step 2 box as shown below.


Step 4: Source List Select

Check those lists which you wish to copy. For the time being I have checked 2 lists.


Please note that the Number of List Items are shown within Parenthesis.

Step 5: Destination Server Connect

In this step input the URL of the Destination Server. You can enter the user name if needed higher permissions. (By default it is SHAREPOINT\system)

You can choose the same Site URL, if you wish to create duplicate items.

You can choose a different Site URL, to create the list and copy the items. Please note that the new List created will be having same List Template & Quick Launch property as the Source List.

For the time being I have created another sub site inside the local host. My URL would be:


After entering the URL click the Refresh button to the right.


You will see the Step4: Finalize section populated with the Source & Destination list names.

Please note that if there is no destination list, a new list will be created & items will be copied.

If there is a destination list with incompatible structure, the copying for the particular list won’t be performed.

Step 5: Copy Items

This step performs the COPY operation. You can see the progress through the progress bar and log message box. Click on the COPY button to start copying.


Within a few seconds the copy operation will be completed and you will get the STATUS BARS updated as shown above. The log box will be displaying the copy operation details.


For reference purpose I have attached the source code for Copy Items along with this article.

Step 6: Verifying the Data

Now we can go back to the new SharePoint site to verify the Lists & Data. You can see that there are 2 new Lists created & items are copied.

Following is the data for Contacts list in the destination site.


Following is the data for Tasks 1 list in the destination site.



The current functionality only allows List items copying. In future Library items copying will be included.

Underlying Code

The underlying code that performs the Copy Items functionality is following method:

private void CopyItem(SPListItem item, SPList destList)


SPListItem newItem = destList.Items.Add();

for (int i = 0; i < item.Fields.Count; i++)

if ((!newItem.Fields[i].ReadOnlyField)

&& (newItem.Fields[i].InternalName != "Attachments"))

newItem[newItem.Fields[i].InternalName] = item[newItem.Fields[i].InternalName];



In case of the Destination List is not existing, we need to create a new List with the same structure. Following is the code that performs the same.

private SPList CreateList(SPWeb sourceWeb, SPWeb destinationWeb, string stitle, string dTitle)


SPList slist = sourceWeb.Lists[stitle];

Guid dguid = destinationWeb.Lists.Add(dTitle, slist.Description, slist.BaseTemplate);

SPList dlist = destinationWeb.Lists[dguid];

dlist.OnQuickLaunch = slist.OnQuickLaunch;


return dlist;


Copying between incompatible list structures are not allowed. The check is performed by the following code:

private bool IsStructureValid()


SPList sourceList = SourceWeb.Lists[SourceListName];

SPList destList = DestinationWeb.Lists[DestinationListName];

for (int i = 0; i < sourceList.Fields.Count; i++)


string fieldName = sourceList.Fields[i].Title;

if (!destList.Fields.Cast<SPField>().Any(f => f.Title == fieldName))

return false;

if (destList.Fields[fieldName].Type != sourceList.Fields[i].Type)

return false;


return true;


This concludes our article on Copy Items add-in for Squadron. I hope this add-in will be useful.



In this article we have explored the Copy Items functionality of Squadron. You are free to download the tool and start using it. As always I am listening for new & new features integration into Squadron.

Posted in C#, SharePoint | Tagged: , | Leave a Comment »

Encounter with Java Guys!!!

Posted by Jean Paul on December 17, 2012

Dear Friends, I would like to share an Interesting Post this Time.  I hope these type of events happens in every Microsoft Buddy’s life.

Yeah! Encounter with Java Guys!!


Sometimes it is worser than dealing with a frustrated customer.. 🙂

Let me come to the matter..

I were given a Team of Java Guys to Talk about the Advantages of SharePoint & Possibly replacing their Document Management System with it.  There were a team of 3 people and me answering their questions.

The senior looking guy, who seems to be like a Manager, shooted this question.

How do you think SharePoint could address the Document Management scenario compared with XYZ solution?

My Reply:  SharePoint supports various Document Management Features like:

  1. I went ahead with a PowerPoint slide presentation & my blogs.

Seems like Mr. Manager not too impressed with my 15 minutes explanations.

He asked me: Can we do custom programming in SharePoint?

I replied: Oh! Yes.. We can do custom programming using .Net

The word .Net created some situation change!

“Oh! We are not interested in .Net.. It is COPIED from JAVA”  He replied.

I wondered a while..

  1. Is this a point worth discussing in this meeting?
  2. Is he some kind of person who creates all things before using it?

(i asked in my mind)

He added..

  • Microsoft is not a technology provider, but a copy provider
  • They stolen Java and made C#
  • They stolen Interpretation and made .Net Runtime
  • Java is mightier & popular than C#
  • Microsoft do not have much technologies with them
  • Whatever they have are not FREE

His Frustration continued.. & It was spiked whenever he sees my MVP Logo on my laptop!

So i just tilted my laptop – hiding the logo, for cooling him off! 🙂

Taking a Step Back

I kept silent for a while..  My past experiences says that people will continue to argue the same point, unless there is correction of root cause & ample time to think on it. The more we address their EGO, the problem will be more WORSER.

I assumed that their Company wanted this Java Team to work in SharePoint and they are not happier to move out from Java.  But the frustration is being poured on this meeting.

So i thought of solving this in a Diplomatic way!

After thinking a few minutes, I declared like this:

Friends.. I appreciate your skills in Java & I like Java.  It is a beautiful language, with lots & lot of quality features.  It was a trend setter for the birth of modern programming languages.  Let me address your questions through my answers here:

Java too is Copied!

I did not personally like the way you called Microsoft as a Copy Cat.  Even Java too was copied..

Java cannot even claim its own Syntax!

  1. Java copied syntax from C language
  2. Java copied OOPS constructs from C++ language


Microsoft was loosing its programming language market due to Java & then they devised .Net.  Microsoft hired the best architect in the world Anders Hejlsberg from Borland for the new platform and Bill Gates was directly involved in the leadership.  So it is not just a copying.  It is enhancing.. It is Innovation!

Interpretation is not a private property of Java

The concept of Interpretation was already there in Microsoft Platform.. It is Visual Basic.  The VBVM  aka Visual Basic Virtual Machine have the Interpretation concept incorporated and was providing faster application runtimes.

So should I say that Java Interpreter concept copied from Visual Basic?

The team went to silent mode.. I enjoyed it. (Violence to Silence)


Again, the Interpretation concept was there in Python language & our old computer science text books too.. So we cannot say anybody copied it.  But everybody implemented it in the best of their ability for addressing customer problems.

Talking about Platform Independence, Java cannot attain Perfect Platform Independence.  The same source code won’t work in different systems like desktop, mobile, different operating system because the underlying presentation sub system, file system, event mechanisms are different.  Till now this platform independence is achieved mostly by web application through HTTP & HTML adding power through client side scripts too.  So Java cannot claim full platform independence as we have to change the code based on platforms.  So i do not wanted to present .Net Mono for Linux against Java!

C# is better than Java

Regarding the quality aspects I would say C# is better than Java.. C# language 4.5 compared with Java 1.7 has following advantages:

  1. Lambda Expressions
  2. LINQ
  3. Delegates
  4. IDE Integrated Entity Framework

Additionally, all those things in Java are there in .Net too:

  1. Annotations as Attributes
  2. Reflection as Reflection
  3. Generics as Generics
  4. java.util as System.Collections
  5. JVM as .Net Runtime
  6. JUnit as NUnit, Visual Studio Unit Tests
  7. Hibernate as NHibernate, Entity Framework
  8. JSP as ASP.NET
  9. J2ME as Windows Phone
  10. Mobile, SWT/Applet as WinForms/WPF

Plus more than 18 languages supported in .Net

Friends, I am telling these as I have worked in Java for a short span of time..  I am assuring you that .Net is better than Java, but as a Java Programmer you need some time in learning the ropes – but first you have to LOVE .Net Platform.

Microsoft have lot of Technologies at Affordable Prices

I was wondering whether he is an ignorant to Microsoft Technologies while saying “Microsoft do not have much technologies”

I replied: Do you know that Microsoft is one of the top 3 technology providers with varieties like:

  1. Desktop Operating Systems
  2. Tablets & Mobile
  3. Office suite like Word, Excel etc.
  4. Programming Platforms like .Net
  5. Languages – C#, VB.NET
  6. Database as SQL Server & Access
  7. Server side like SharePoint, BizTalk, Exchange etc.
  8. Publishing with Visio, PowerPoint etc.
  9. Gaming arena with XBOX
  10. Bing Search Engine, Outlook, Azure etc.

Seems like there is no reply, but only WONDERMENT on the array of technologies..


But he defended this time by saying.. “Why they are not Free?  Who will purchase them?”

This is a serious question and as I faced the same years back, I had thought about the answer.


It is true that Java is more popular than C#, more developers are using it.. But it does not mean that it is the Mightier one!

There are only few BMWs on the road, do that means others are mightier?

If it was Free, then it won’t exist

I replied, My dear friend, I wanted you to make an unbiased look on the following:

Java is free, but for core consultation there is a price by the company

Java is free, but you developers are not free..

Tell me one thing.. Are you ready to work for FREE?  No.. Right? (you cannot pay your rent, utility bills if you work for free)

Talking from a Business Evaluator perspective, A mere Free Java is of no use.  For creating applications, A business has to add computers, internet, hire developers, rent work space  spend on development time, spend on maintenance costs.  So the tool like Java / .Net is only a portion of the money in right cases a paid tool will be more effective in the long run in reducing costs & increasing quality. The effect will vary based on larger projects.

Additionally Java Developers are of higher cost than .Net guys.  So in specific scenarios where Java Developer Rates are High, Java Development Costs are high, Java Resources are Rare, it adds higher costs to development using Java.  So .Net would be a better choice in this case.



Your company might save cost in choosing Java as the IDE & Language are free.. But they spend money in hiring developers & more money in developing efforts.  So in the long run .Net is better than Java.. This is the reason why .Net is selling even though it is not Free!

I gently questioned him: So why you are blaming others for not selling their things for free?

It is the company strategy, to sell something for money or for free.

You can see that things were free and now Sun was acquired by Oracle.  In the stock market terms, a company is ready to be sold only if they loose confidence in future profits.. So your Java & Sun was sold to Oracle..  They lost the competition.  Now why you are fighting for Java.. Come on.. Forget the Past.. Welcome the future with SharePoint..


Seems like the Mr. Manager is silent now.. no questions, no answers..

I thought of ending the session in that positive note.. meantime one of his team member RISED FROM THE GRAVE and SAID:

“PHP is better than .Net. PHP is light, it is fast, it is free.. What do you wanted to say about that?”

I was Shocked!  I remembered a proverb suddenly, Escaped from a KING COBRA and bitten by a LIZARD.


(I just vanished from the scene :))


I wanted to say that this is not any Personal Vengeance against Java.  But just an unbiased, 500 feet view of both the technologies.  I feel all technologies are good based on the solution & availability of resources.   But Still I recommend Microsoft Technologies as it is Cool, Affordable, Profitable in Long Run 🙂

Posted in C#, SharePoint | Tagged: , | 22 Comments »

SharePoint Copy List Items in a Generic Way

Posted by Jean Paul on December 15, 2012

In this article we can explore the scenario of copying List Items in a Generic Way.

The generic way provides solution in such a way that:

· No Hard Coding of List Columns

· Ensures Read Only columns are not updated in Destination list

· It provides easier way of creating duplicate items

Source List

For our example following is the source list of type Contacts.


Destination List

For the time being we are using the same source list as the destination list. This will create duplicate items in the Contacts list.


Create a new Console Application, change the Target Platform to Any CPU and add the following code in the Program.cs file Main() method.

static void Main(string[] args)


using (SPSite site = new SPSite("http://localhost&quot;))


using (SPWeb web = site.OpenWeb())


CopyItems(web, "Contacts", "Contacts");




private static void CopyItems(SPWeb web, string sourceListName, string destListName)


SPList sourceList = web.Lists[sourceListName];

SPList destList = web.Lists[destListName];

foreach (SPListItem item in sourceList.Items)

CopyItem(item, sourceList);


private static void CopyItem(SPListItem item, SPList destList)


SPListItem newItem = destList.Items.Add();

for (int i = 0; i < item.Fields.Count; i++)

if ((!newItem.Fields[i].ReadOnlyField) && (newItem.Fields[i].InternalName != "Attachments"))

newItem[newItem.Fields[i].InternalName] = item[newItem.Fields[i].InternalName];



Code Explained

The main method connects to the SharePoint site and invokes CopyItems method. In the method the source and destination list names are passed.

CopyItems(web, "Contacts", "Contacts");

Inside the CopyItems method each SPList objects are constructed using the list names. Then using a foreach loop the items from source list are fetched.

Each item is passed to the CopyItem method. Inside this method, each field of source item is iterated and copied to the destination item. The Internal Name of the field is used to avoid field order variation problems.


Each list contains a field named Attachment which will be throwing exception while assigning. We are explicitly checking and removing this field.


On executing the application, we can see that a duplicate item is created in the Contacts list. (please ensure you have at least one item in the source list).


Executing multiple times will create duplicate number of items.

This concludes our article on copying list items in a generic way. I hope you enjoyed the code.



In this article we have explored the code for copying items in a generic way. In the real life scenario this should help as an alternative to Save List as Template feature, creating duplicate list items.

The source code is attached with the article. I will be integrating this functionality to our Squadron tool for SharePoint.

Posted in C#, SharePoint | Tagged: , | Leave a Comment »

Server Error in ‘/’ Application.

Posted by Jean Paul on December 13, 2012

Server Error in ‘/’ Application.

Runtime Error

Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed. 

Details: To enable the details of this specific error message to be viewable on the local server machine, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "RemoteOnly". To enable the details to be viewable on remote machines, please set "mode" to "Off".


<!– Web.Config Configuration File –>




        <customErrors mode="RemoteOnly"/>



Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application’s <customErrors> configuration tag to point to a custom error page URL.


<!– Web.Config Configuration File –>




        <customErrors mode="On" defaultRedirect="mycustompage.htm"/>




The Problem

Sorry for the lengthy error message.  One of my colleague mentioned about the problem.  He is new into SharePoint and was having ASP.NET background.

Changing the INETPUB web.config was not solving the problem. (making customErrors mode=”Off”)

Locations of Configuration Files

SharePoint had a series of web.config files.  Following are the locations:

  1. C:\inetpub\wwwroot\wss\VirtualDirectories\80
  2. C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS

More Info:


The Solution

To modify the customErrors mode to Off, please go to the LAYOUTS folder.


Open the web.config file and modify the customErrors mode to Off.


Now you can retry the request, this time you should be getting the exact error message.

Good Luck My Friend!

Posted in C#, SharePoint | Tagged: , | Leave a Comment »

Send Keys to SharePoint site Programmatically using C#

Posted by Jean Paul on December 11, 2012

In this article we can explore a scenario I have encountered while working with SharePoint.



My client had a Production issue where the Request Tracking report is too huge in size and cannot be downloaded. Although the problem is fixed, we need to test this in our UAT environment.

To test this we need 1000 requests logged in the SharePoint site. How to create the 1000 requests?

I had the following interesting ideas & solutions.

Idea 1: Create an SQL stored procedure that inserts 1000 records to the Content Database.

Problems: Content Database access issue, directly modifying is not recommended

Idea 2: Create a web part that inserts records into the Audit Log using Server Object Model

Problems: Some of the fields will remain null

Idea 3: Click the browser refresh button for 1000 times

Problems: Too hectic for a human to perform

Idea 4: Place a lock on the F5 key

Problems: The site requires 3 seconds for loading, so skips all the key requests if continuous

Idea 5: Create a Web Client automation

Problems: The site is under security proxies. So the URL automation is not possible.

Idea 6: Send Keys to Browser

Action: Feasible

I selected the Idea 6 as the site is authenticated in a browser window. Through a separate windows application we can send Refresh keys (F5) on regular intervals using Windows API.


Windows API invocation can be done in .Net using Platform Invoke infrastructure.

The Steps

Following are the steps involved in the application.

1. Find the Window Handle using the Title

a. For example: “Bing – Windows Internet Explorer” is the title of Internet Explorer while opening website

2. Make the Window as Active Window

a. Use the SetForegroundWindow API method to make the window as active, so that we can send keys to active window

3. Send the Key to the window

a. Send Key (F5) to the active window

4. Repeat the loop

a. Continue the loop with an interval specified by the user.

The Code

Following are the Windows API methods required by our application.

[DllImport(“user32.dll”, EntryPoint = “FindWindow”, SetLastError = true)]

public static extern IntPtr FindWindow (IntPtr ZeroOnly, string lpWindowName);


public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, IntPtr dwExtraInfo);


[return: MarshalAs(UnmanagedType.Bool)]

static extern bool SetForegroundWindow(IntPtr hWnd);

Following is the code to get the Window Handle by caption.

_pointer = FindWindow(new IntPtr(0), TitleText.Text);

If the _pointer has a value greater than 0, we are good to have a valid Handle.


A handle (HWND) is the return value from CreateWindowEx which the Windows Operating System uses to identify a window.


The UI

Create a windows forms application and set the following controls.


On the start button click add the following code.

private void StartButton_Click(object sender, EventArgs e)




private bool _start;

private int _count;

private void Start()


_start = true;

StartButton.Enabled = false;

StopButton.Enabled = true;


while (_start)



Thread.Sleep(int.Parse(textBox3.Text) * 1000);




public void SendKeys()


int key = int.Parse(KeyText.Text);

const int KEYEVENTF_KEYUP = 0x0002;

keybd_event((byte)key, 0, 0, IntPtr.Zero);

keybd_event((byte)key, 0, KEYEVENTF_KEYUP, IntPtr.Zero);


// The keybd_event() method SENDS the key


The Implementation

Open a browser and browse to our SharePoint site. Ensure you have logged in correctly.


Now execute our application and enter the title of the Browser in the application. In this case it is: “Reports – All Documents – Windows Internet Explorer”


Enter the Key value. For F5 key, it is ASCII 116. Set the Interval as 4 seconds which will create around 900 requests per hour.

After setting the values click the Start button. You will see that the browser is made as foreground window and the Refresh process starts repeating every 4 seconds. (Observe the Refresh of browser status bar)




In this article we have explored a Send Key scenario with Windows API as the solution. You can comment on better ideas for the problem.

The source code for the article is attached along with.

Posted in C#, SharePoint | Tagged: , | 2 Comments »

SharePoint 2010 – Create a List in C# based on another List

Posted by Jean Paul on December 10, 2012

We can create copy of a List from one SharePoint site to another using List Template Exporting & PowerShell. In this article we can see the Server Object Model way of achieving the same.

Classes Involved

The SPList class is the core type involved in our functionality.

Activities Involved

Following are the activities involved in our application.

Step 1: Create a List in SharePoint site based on the Tasks template and name it as Tasks 1.


Step 2: Create a console application

Add reference to the Microsoft.SharePoint assembly


Set the Build > Platform Taget to Any CPU


Step 3: Add the following code

In the Program.cs add the following code.

class Program


static void Main(string[] args)


using (SPSite site = new SPSite("http://localhost&quot;))


using (SPWeb web = site.OpenWeb())


SPList sourceList = web.Lists["Tasks 1"];

Guid destGuid = web.Lists.Add("Tasks 2", sourceList.Description, sourceList.BaseTemplate);

SPList destList = web.Lists[destGuid];

destList.OnQuickLaunch = sourceList.OnQuickLaunch;






The above code performs the following:

1. Create the SPSite & SPWeb objects

2. Access the Tasks 1 list

3. Create a new Tasks 2 list using the Template of first list

4. Set the Quick Launch property to true

5. Update the new List

6. Disposes the SPSite & SPWeb objects

Step 4: View the new List created

Now you can go back to the SharePoint site and see the new list was created.



The SPList server object model contains the BaseTemplate instance property as the List Template. We are creating the new list using this property.

web.Lists.Add("Tasks 2", sourceList.Description, sourceList.BaseTemplate);



In this article we have explored the Server Object Model of creating List based on another List.

Posted in C#, SharePoint | Tagged: , | Leave a Comment »

How to Create a Document Library & Insert a new File?

Posted by Jean Paul on December 4, 2012

Dear Friends, I was searching for a quick code to create a document library & insert a file into it. 

Following is the code that accomplishes the same.

using System;
using Microsoft.SharePoint;
using System.IO;
using System.Linq;

namespace ConsoleApplication6
    class Program
        static void Main(string[] args)
            using (SPSite site = new SPSite("http://localhost"))
                using (SPWeb web = site.OpenWeb())
                    string title = "Document Library";

                    if (!web.Lists.Cast<SPList>().Any(l => l.Title == title))
                        web.Lists.Add(title, string.Empty, SPListTemplateType.DocumentLibrary);

                    SPDocumentLibrary library = web.Lists[title] as SPDocumentLibrary;

                    library.RootFolder.Files.Add("MyFile.txt", new byte[3] { 65, 66, 67 }, true);


After running the code you can see that:

  1. New Document Library created
  2. New File created inside it

You have to use the All Site Content to view this document library as the Quick Launch property is false.




Posted in C#, SharePoint | Tagged: , | 2 Comments »