65.9K
CodeProject is changing. Read more.
Home

Developing Sharepoint Windows Forms

starIconstarIconstarIconstarIconstarIcon

5.00/5 (1 vote)

Mar 23, 2013

CPOL

2 min read

viewsIcon

30192

downloadIcon

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 

 

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

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

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

 

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

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; 

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.

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();

            }

        } 

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

 

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