Wednesday, May 8, 2013

Developing Sharepoint Windows Forms

Intro:


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 


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


STEP 1:

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


STEP 2:

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


STEP 3:

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


STEP 4:

In the Build tab change the platform target to Any CPU


STEP 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


STEP 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; 



STEP 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.


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



STEP 9:

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



No comments:

Post a Comment