Archive

Posts Tagged ‘Web Part’

Code samples from: – SharePoint Conference 2009, "Advanced Development for Silverlight 3 in SharePoint 2010"

Code samples from:
- SharePoint Conference 2009, "Advanced Development for Silverlight 3 in SharePoint 2010"
- MSDN Webcast Feb 2010, "Developing Rich Solutions in Silverlight for SharePoint 2010"
- ReadMe.docx

This release includes a recording of the MSDN Webcast,

“Developing Rich Solutions in Silverlight for SharePoint 2010”

along with the code shown in the webcast. These are updates of the same solutions shown at SharePoint Conference 2009 in the talk, “Advanced Development for Silverlight 3 in SharePoint 2010”; this Code Gallery release will serve to provide the sample code from both talks.

The code samples are as follows:

SharePoint and Silverlight from Scratch

This walkthrough was presented only in the webcast to show how to get stared developing in Silverlight for SharePoint 2010. The sample includes only the snippets (in Visual Studio snippet format); it will be necessary to watch the webcast to see how to use them.

Picture View Web Part

This is a Silverlight web part that shows a slide show of images stored in a SharePoint picture library. This demonstrates how to use the HTML bridge to reduce the number of round-trips to the server. In this case, the server side web part passes the URL’s of the pictures to Silverlight in a hidden form field, removing the need for the Silverlight application to query the server for the list of pictures.

Paged List View Web Part

This is a Silverlight web part that shows a grid of data from a SharePoint list. It allows paging, sorting and filtering, and only loads an n-row page at a time to allow viewing a large data set without downloading the whole thing to Silverlight. In addition to loading the first “page” of data in a hidden field (like the Picture View web part) , it obtains additional content using ADO.NET Data Services and SharePoint’s new RESTful interface.
NOTE this release does not include the target list, and the sample will not run without it. A future release may include a matching list definition with sample data.

Video Field Control

This adds a Video field to SharePoint, using Silverlight applications to view and select the video. The actual field simply stores the URL of the video. The Silverlight display application is very simple, and just plays the video based on this URL. The selector application is more interesting as it uses the client object model to provide a simple browsing and preview feature in which the user can select a site, library and video to be shown.

Connected Silverlight Web Parts

This sample includes a pair of web parts – a source and target. When connected via the web browser, text entered into the source web part will appear on all targets as it is typed. This shows how to use SharePoint’s web part connection mechanism – which runs on the server side – as a broker to connect the Silverlight applications. The Silverlight applications communicate using the new Silverlight 3.0 Local Messaging API.

 

Extracted from

http://code.msdn.microsoft.com/SP2010Silverlight

February 11th, 2010 Neal McFee No comments

SharePoint 2010 Samples for Visual Studio 2010 Release Candidate

Visual Studio 2010 Release Candidate samples demonstrate SharePoint 2010 development projects, tools, and techniques. Each sample is available in both Visual Basic and C#.

SharePoint samples

SharePoint 2010 Sequential Workflow
Demonstrates how to create a basic sequential workflow template that associates a task in the SharePoint Tasks list with a document in a document library.

Business Data Connectivity Samples
Shows how to use custom Business Data Catalog types in a SharePoint project.
Visual Web Part
Shows how to create an ASP.NET Web part that can be used in SharePoint.

List with Event Receiver
Demonstrates how to use a list definition, list instance, content type, event receiver, visual Web part, LINQ to SharePoint, and Package Designer to create an equipment lending library based on SharePoint 2010.

Custom Action Project Item
Demonstrates how to add a new SharePoint Project Extension using the SharePoint project extensibility APIs that are part of Visual Studio 2010.

Visual Web Part
Shows how to create an ASP.NET Web part that can be used in SharePoint.

February 11th, 2010 Neal McFee No comments

Walkthrough 2: Building a Web Part for a Sandboxed Solution

 

Exercise Duration: 20 minutes

Exercise Overview

This exercise demonstrates creating a web part that renders and updates list data that is deployed as a Sandboxed Solution.

Feature Overview  

A sandboxed solution can be deployed to a site by a site administrator, without requiring intervention from the farm administrator. The solution has full access to the immediate site and restricted access to system resources and other sites.

Task 1: Create Sandboxed Solution Project with a webpart.

1. Open Visual Studio 2010 from the Start | Programs | Visual Studio 2010 menu.

2. Create a new project by using File | New Project.

3. Pick the SharePoint | 2010 templates.

4. From the SharePoint | 2010 templates select the Empty Project project template.

5. Use SBSolutionDemo as the name.

6. Set the location to be C:\SPHOLs.

7. Press OK to create the project.

image

8. When the SharePoint Customization Wizard dialog appears, select the site you want to deploy the Web Part to.

9. Select the Deploy as a sandboxed solution radio button

10. .Press the Finish button to complete the project creation process.

image

 

11. Right-click on the SBSolutionDemo project in the Solution Explorer and choose Add | New Item.

12. Select the Web Part (not the Visual Web Part) template from the SharePoint | 2010 templates in the Add New Item dialog.  Name it SBWebPart.  

image

13. Press OK to close the dialog and add the item to the project.

 

Task 2: Add code to provide querying and rendering functionality.

1. In the Solution Explorer, double-click on the SBWebPart.cs file to open it in the editor window.

2. Add the following using statement after the other using statements.

 

 

using System.Web.UI.HtmlControls;

 

3. Add the following variables to the class declaration.

 

DropDownList _ddlProjects = new DropDownList();

TextBox _tbDescription = new TextBox();

TextBox _tbDueDate = new TextBox();

 

4. Add the following new methods within the class declaration.

 

protected override void OnLoad(EventArgs e)

{

    base.OnLoad(e);

    if (!Page.IsPostBack)

        GetProjectDetails();

}

 

/* Populate the text boxes with the selected project details */

private void GetProjectDetails()

{

    EnsureChildControls();

    if (_ddlProjects.SelectedValue != "– Select a Project –")

    {

        SPList pList = SPContext.Current.Web.Lists["Projects"];

        int nProjectID = Convert.ToInt32(_ddlProjects.SelectedValue);

        SPListItem spliProject = pList.GetItemById(nProjectID);

        _tbDescription.Text = spliProject["Description"].ToString();

        DateTime dueDate = Convert.ToDateTime(spliProject["Due_x0020_Date"]);

        _tbDueDate.Text = dueDate.ToShortDateString();

    }

    else

    {

        _tbDescription.Text = String.Empty;

        _tbDueDate.Text = String.Empty;

    }

}

 

5. Add the following CreateChildControls implementation beneath the previous code (replace the existing CreateChildControls method).

 

/* Build the UI and setup events */

protected override void CreateChildControls()

{

    base.CreateChildControls();

    Panel parent = new Panel();

    parent.Style.Add("border", "solid 1px Navy");

    parent.Style.Add("background-color", "#EEEEEE");

    parent.Style.Add("width", "250px");

    _ddlProjects.ID = "ddlProjects";

    _ddlProjects.AutoPostBack = true;

    _ddlProjects.SelectedIndexChanged += new 

    EventHandler(ddlProjects_SelectedIndexChanged);  

    PopulateProjects();

    parent.Controls.Add(_ddlProjects);

 

    Panel panel = new Panel();

    Label label = new Label();

    label.Text = "Description";

    panel.Controls.Add(label);

    parent.Controls.Add(panel);

    panel = new Panel();

    panel.Controls.Add(_tbDescription);

    parent.Controls.Add(panel);

 

    label = new Label();

    label.Text = "Due Date";

    panel = new Panel();

    panel.Controls.Add(label);

    parent.Controls.Add(panel);

 

    panel = new Panel();

    panel.Controls.Add(_tbDueDate);

    parent.Controls.Add(panel);

 

    panel = new Panel();

    Button bUpdateProject = new Button();

    bUpdateProject.Text = "Update Project";

    bUpdateProject.Click += new EventHandler(bUpdateProject_Click);

    panel.Controls.Add(bUpdateProject);

    parent.Controls.Add(panel);

    Controls.Add(parent);

}

 

6. Add the following code beneath the CreateChildControls method:

 

 

/* Populate the projects drop down */ 

private void PopulateProjects()

{

    SPList splProjects = SPContext.Current.Web.Lists["Projects"];

    _ddlProjects.Items.Add("– Select a Project –");

    foreach (SPListItem spli in splProjects.Items)

    {

        _ddlProjects.Items.Add(new ListItem(spli.Title, spli.ID.ToString()));

    }

}

 

7. Add the following event handling code beneath the PopulateProjects method:

 

 

/* Change projects handler */

void ddlProjects_SelectedIndexChanged(object sender, EventArgs e)

{

    GetProjectDetails();

}

 

/* Update the current project */

void bUpdateProject_Click(object sender, EventArgs e)

{

    EnsureChildControls();

    int nProjectID = Convert.ToInt32(_ddlProjects.SelectedValue);

    SPListItem spliProject = 

    SPContext.Current.Web.Lists["Projects"].GetItemById(nProjectID);

    spliProject["Description"] = _tbDescription.Text;

    spliProject["Due_x0020_Date"] = _tbDueDate.Text;

    spliProject.Update();

}

 

Task 3: Build and Deploy the Sandboxed Solution.

1. Right-click on your project in the Solution Explorer and select Deploy. 

2. Browse to your server. Click Site Actions | Site Settings  .  Then click on  Solutions (under Galleries), you will see your sandboxed solution deployed and activated. 

 

image

 

3. Add the webpart to a webpart page.

Click the Edit button to put the page in edit mode. 

Click Insert

Click Web Part

Click Miscellaneous

Click the SBWebPart Title

Click Add 

 

image

 

4. Now you will see the web part running in the Sandboxed Solution. Click the drop down to select a project. The description and due date fields are both updatable.

 

image

 

Exercise Summary

In this walkthrough you built and deployed a Web Part that runs in the context of a Sandboxed Solution.

  

February 10th, 2010 Neal McFee No comments