Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

Developing Sharepoint Windows Forms

4.67/5 (2 votes)
23 Mar 2013CPOL2 min read 30.2K   510  
Steps How to Develop Sharepoint Windows Forms

 Download WFASolution.zip

Introduction  

this Tip is for all developers who would like to make a user friendly Interface using sharepoint sites and Objects.

developing a windows Form is a good choice when it comes to fast interactive tool instead of using Basic console Application 

Background 

I'm going to list the steps in details to create the windows form
Application and how does it support Sharepoint Objects model.  

Steps: 

1.      
First go to Visual Studio 2010 and Create New Project choose the programming language for example C# then choose Windows Forms  Application 

Image 1

 

2.      
Rename the Project ,then when it is created right click the Project to edit the properties 

Image 2

3.      
In the Application tab choose the target frame work  .net FrameWork 3.5.

Image 3

 4.      In the Build tab change the platform target to Any CPU

 Image 4

5.      
Right click references and add
sharepoint references, Microsoft.SharePoint .dll,
Microsoft.SharePoint.Client, Microsoft.SharePoint.Client.Runtime

select Browse go to the 14%  (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI

Image 5

6.
 
right click the Form and select view code to go to the CS file then Add the using statement in the CS file  

using Microsoft.SharePoint; 

Image 6

7.    Design the form (add the controls , labels, textboxes…etc.) I have designed a simple form with 2 labels 1 text box and 1 button.

Image 7

8.  If you have button just right click the button and choose view code insert the sharepoint  code in the button action . 

this is only a simple code that will ask the user to enter URL and click on the button that will display the title of the Site. 

   private void button1_Click(object sender, EventArgs e)

        {

            //ask the user to enter Site Collection URL

            string SiteURL = textBox1.Text;

            using (SPSite SiteCollection = new SPSite(SiteURL))

            {

                label2.Visible = true;

               label2.ForeColor = System.Drawing.Color.Green;

                label2.Text = "Site Collection URL is :" + SiteCollection.RootWeb.Title.ToString();

            }

        } 

Image 8

9. you are done now , only run the solution and you can display the windows form

Image 9 

10. you can find the project sample in the Source attached to this article.


License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)