Вы находитесь на странице: 1из 97

.

,
, URL- - ,
. , , .
, ,
.
.
-
.
.
(Microsoft Corporation), 2010. .
Microsoft, SharePoint, Visual Studio, InfoPath Visio
. .

SharePoint 2010

1. - Linq ......................................... 4
1. SharePoint ............................................................................................ 4
2. - LINQ-to-SharePoint ....................... 7
3. SharePoint - ........................................... 10
4. - ................................................................ 12
2. BCS ............................................................................. 17
1. - ................................................................. 17
2. ........................................................................................ 18
3. ............................................................................................................ 29
4. ...................................................................................................... 31
3. Silverlight SharePoint ............... 35
1. Silverlight ................................................................................... 35
2. SharePoint ................. 37
3. - SharePoint Silverlight ........................................ 41
4. SharePoint
Silverlight ......................................................................................................................................... 43
1. Silverlight ................................................................................... 43
2. Employee SharePoint
Silverlight Graph ........................................................................................................ 47
3. - SharePoint Silverlight
.................................................................................................................................................. 50
5. - .............................................................. 54
1. - ...................................................... 54
2. , .................................................. 56
3. .......................................................... 59
6. SharePoint .... 64
1. ................................................................................................... 64
2. ,
............................................................................................................................ 66
3. , ,
................................................................................................................................. 68
4. . ..................................................................................... 71
5. SPDActivityDemo,
SPCHOL305Ex1. ............................................................................................................................................. 76
6. ................................................ 78
7. .................................................................................. 78
8.
SharePoint ....................................................................................................................................................... 79
9. Visual Studio ........................... 87
10. SharePoint ................................................. 94
................................................................................................................ 97

SharePoint 2010

, C#,
Visual Studio 2010
SharePoint 2010.
,
,
.
eLearning: http://msdn.microsoft.com/ru-ru/sharepoint/ee513148.aspx
(, ).
, , ,
, C#, VB.NET.

sp2010fb@Microsoft.com.

SharePoint 2010

1. -
Linq
: 10
-,
DataGrid.
:
1. -.
2. - Linq.
3. Linq SharePoint.
4. - SPDataGrid.
1. SharePoint
.
1 .
1. Visual Studio 2010, | |
Microsoft Visual Studio 2010 | Microsoft Visual Studio 2010.
2. | | .
3.
Visual C# | SharePoint | 2010.
4. -.

SharePoint 2010

1. - SharePoint 2010

5. SPCHOL200-Ex1.
6. C:\SPHOLS\SPCHOL200\CS\Ex1.
7. .
8. OK.
9. SharePoint .

http://intranet.contoso.com/ .

SharePoint 2010

2. SharePoint

10. Visual Studio SPCHOL200-Ex1


.

3. SPCHOL200-Ex1

SharePoint 2010

11. , Visual Studio -


VisualWebPart1. VisualWebPart1
VisualWebPart1.webpart.

4. -

12. Title SPLinqDemoTitle,


Description SPLinqDemoPart Description.
Title Description - . .
<properties>
<property name="Title" type="string">SPLinqDemoTitle</property>
<property name="Description" type="string">SPLinqDemoPart Description</property>
</properties>

2. - LINQ-to-SharePoint

spmetal.exe - Linq-to-SharePoint.
1. SPCHOL200-Ex1
Windows.
2. Shift -
, ,
:

SharePoint 2010

5.

3. ,
SharePoint 2010:
set path=%path%;c:\program files\common files\microsoft shared\web server
extensions\14\bin
4. ,
- Linq-to-SharePoint:
spmetal.exe /web:http://intranet.contoso.com /namespace:SPCHOL200_Ex1.VisualWebPart1
/code:SPLinq.cs

.
. .
5. Visual Studio.
6. Visual Studio SPCHOL200-Ex1
| .

6.

7. SPLinq.cs
:

SharePoint 2010

7. SPLinq.cs

8.
.
9. C:\Program Files\Common Files\Microsoft
Shared\Web Server Extensions\14\ISAPI . ,
. ,
8.
10. Microsoft.SharePoint.Linq.dll.

SharePoint 2010

8.

11. OK, .
3. SharePoint -
, -
SharePoint.
1. VisualWebPart1
VisualWebPart1UserControl.ascx.
2. Visual Studio Visual Web Part.
3. ,
.

10

SharePoint 2010

<%@ Import Namespace="Microsoft.SharePoint.WebControls" %>


<SharePoint:SPGridView id="spGridView" runat="server"
AutoGenerateColumns="false">
<HeaderStyle HorizontalAlign="Left" ForeColor="Navy" Font-Bold="true" />
<Columns>
<SharePoint:SPBoundField DataField="Title"
HeaderText="Title"></SharePoint:SPBoundField>
<SharePoint:SPBoundField DataField="JobTitle"
HeaderText="JobTitle"></SharePoint:SPBoundField>
<SharePoint:SPBoundField DataField="ProjectTitle"
HeaderText="ProjectTitle"></SharePoint:SPBoundField>
<SharePoint:SPBoundField DataField="DueDate"
HeaderText="DueDate"></SharePoint:SPBoundField>
</Columns>
</SharePoint:SPGridView>

: ASP.NET | spchol200_ex1_spgridview
4. Visual
Web Part :

9. Visual Web Part

5.
VisualWebPart1UserControl.ascx .
6. using :
using Microsoft.SharePoint.Linq;
using Microsoft.SharePoint;
using System.Linq;

: My Code Snippets | spchol200_ex1_namespaces


7. Page_Load :
var dc = new SPLinqDataContext(SPContext.Current.Web.Url);
var Employees = dc.GetList<EmployeesItem>("Employees");

11

SharePoint 2010

var empQuery = from emp in Employees


where emp.Project.DueDate <
DateTime.Now.AddMonths(6)
select new
{
emp.Title,
emp.JobTitle,
ProjectTitle = emp.Project.Title,
DueDate =
emp.Project.DueDate.Value.ToShortDateString()
};
spGridView.DataSource = empQuery;
spGridView.DataBind();

: My Code Snippets | spchol200_ex1_pageload


4. -
1. SPCHOL200-Ex1
. -
SharePoint: http://intranet.contoso.com

10. -

2. Internet Explorer :
http://intranet.contoso.com
3. , .
: Administrator
: pass@word1
4. , SharePoint
.

12

SharePoint 2010

11. SharePoint

12. SharePoint

5. -,
- .

13

SharePoint 2010

13. SharePoint -

6. .
7. - - SPLinqDemoTitle.

14. - SPlinqDemoTitle

, -.
, -.

14

SharePoint 2010

15.

8. , - . -
SPLinqDemoTitle .

15

SharePoint 2010

16. - SPLinqDemoTitle

9. , ,
,
.
.

17. SharePoint

10. Internet Explorer.


11. Visual Studio 2010.
, Linq to SharePoint SharePoint.
16

SharePoint 2010

2. BCS

- Visual Studio 2010
.
1. -
1. Visual Studio 2010, | |
Microsoft Visual Studio 2010 | Microsoft Visual Studio 2010;
| | .
2. Visual C# | SharePoint | 2010 |,
-.
3. BDCEx1.

18.

4. C:\SPHOLS\SPCHOL304\CS\Ex1.
5. OK.

17

SharePoint 2010

6. URL- http://intranet.contoso.com.
7. .

19. SharePoint

8. .
2.
1. | .
, Entity1.cs Customer.cs,
Entity1Service.cs CustomerService.cs.
:

18

SharePoint 2010

20. Visual Studio

2. Customer.cs, .
Customer .

, -.
, Identifier1 CustomerId ,
, Identifier1.
, .

public
public
public
public

Int32 CustomerId { get; set; }


string Message { get; set; }
string FirstName { get; set; }
string LastName { get; set; }

: My Code Snippets | spchol304_ex1_customer

21. Customer

19

SharePoint 2010

3. BCS
1. BdcModel1.bdcm,
- .

22. , BDCModel1.bdcm
-.

2. Entity1, .

23. Entity1

3. Entity1 Customer, Entity1


F2 ( ).
4. Identifier1 F4,
. Identifier1 CustomerId
System.Int32.

20

SharePoint 2010

24.

5. - Visual Studio
| BDCModel1 | BDCModel1 | Customer | ReadList | returnParameter.
Entity1List, .

25. - Entity1List

6. Entity1List CustomerList.

21

SharePoint 2010

7. - CustomerList.

26. - Entity1

8. Entity1 Customer.
- Customer
Identifier1 CustomerId TypeName
System.Int32.

22

SharePoint 2010

27. Identifier1

9. -
Customer .

28. Customer

10. TypeDescriptor
Name FirstName.
11. -
Customer .
12. TypeDescriptor
Name LastName.

29. Customer -
FirstName LastName

13. -
Customer .

30. Customer

14. - ReadItem,
returnParameter .

23

SharePoint 2010

31. returnParameter

15. .

32.

16. returnParameter | Customer ,


FirstName LastName .

24

SharePoint 2010

33. - , 1-
18- 1

25

SharePoint 2010

17. -
ReadItem | id Identifier1.
18. Identifier1 CustomerId
TypeName System.Int32.

34. Identifier1

19. -

35.
-

26

SharePoint 2010

20. id

36. id

27

SharePoint 2010

21. .
22. @id ReadItem,
CustomerId, @id Update.
23. Pre-Updater id, True.

37. Pre-Updater True

28

SharePoint 2010

3.
1. CustomerService.cs.
2. CustomerService .
,
.

public static Dictionary<Int32, Customer> d = null;


public static Customer ReadItem(Int32 id)
{
// take a copy for SharePoint
Customer c = new Customer();
Customer e = d[id];
c.CustomerId = e.CustomerId;
c.FirstName = e.FirstName;
c.LastName = e.LastName;
c.Message = e.Message;
return c;
}
public static IEnumerable<Customer> ReadList()
{
// this is usually the first method called so check for null
if (d == null)
{
d = new Dictionary<Int32, Customer>();
for (int i = 0; i < 10; i++)
{
Customer e = new Customer();
e.CustomerId = i;
e.Message = i + " Item Data";
e.FirstName = i + " First Name";
e.LastName = i + " Last Name";
d.Add(i, e);
}
}
return d.Values;
}
public static void Update(Customer customer, Int32 id)
{
d[id].FirstName = customer.FirstName;
d[id].LastName = customer.LastName;
d[id].Message = customer.Message;
}

: My Code Snippets | spchol304_ex1_customerservice


29

SharePoint 2010

38. CustomerService

3. Features
Feature1.feature. .
4. .
5. + ,
.
6. (Property) URL- .
<Property Key="SiteUrl" Value="http://intranet.contoso.com" />

30

SharePoint 2010

39.

39. SiteUrl

4.
1. | BDCEx1.
2. http://intranet.contoso.com .
3.

40.

4. .

41.

31

SharePoint 2010

External List .

42.

5. .
6. (
).

43.

32

SharePoint 2010

7. BDCEx1.BDCModel1.Customer OK.

44. - -

45.

33

SharePoint 2010

8. .
9.
.

46. ( -)

34

SharePoint 2010

3. Silverlight
SharePoint
Silverlight,
SharePoint . ,
Silverlight SharePoint. Visual
Studio 2010, SharePoint.
1. Silverlight
Silverlight.
1. Visual Studio 2010, | |
Microsoft Visual Studio 2010 | Microsoft Visual Studio 2010.
2. | | .
3.
| Visual Studio |
.
4. .NET Framework 3.5
5. Begin.
6. C:\SPHOLS\SPCHOL306\CS\Ex1\.

47.

35

SharePoint 2010

7. OK, .
8. | | .
9.
Visual C# | Silverlight,
Silverlight .
10. .NET Framework 3.5
11. SPSilverlightExample.
12. .

48.

13. OK, .

49. Silverlight

36

SharePoint 2010

14. OK, .
15. SPSilverlightExample
SharePoint Silverlight.
SPSilverlightExample .
16. C:\Program Files\Common Files\Microsoft Shared\Web Server
Extensions\14\TEMPLATE\LAYOUTS\ClientBin.
17. Microsoft.SharePoint.ClientSilverlight.dll
Microsoft.SharePoint.Client.Silverlight.Runtime.dll ( CTRL,
).
18. OK, DLL.

50.

2. SharePoint
1. Visual Studio
Silverlight.
2. DataGrid Silverlight
Page.xaml.

37

SharePoint 2010

51. Silverlight

3. DataGrid , ,
Width Height Auto, HoriztonalAlignment
VerticalAlignment Stretch, Margin 0.

52. DataGrid

38

SharePoint 2010

4. AutoGenerateColumns ( XAML
true).

53. AutoGenerateColumns

5. App.xaml.cs using:
using Microsoft.SharePoint.Client;
using System.Threading;

: My Code Snippets | spchol306_ex1_app_namespaces


6. Application_Startup.
ApplicationContext.Init(e.InitParams, SynchronizationContext.Current);

: My Code Snippets | spchol306_ex1_ application_startup


7. MainPage.xaml.cs
using:
using Microsoft.SharePoint.Client;

: My Code Snippets | spchol306_ex1_page_namespaces


8. MainPage :
public class Project
{
public string Title { get; set; }
public DateTime DueDate { get; set; }
public string Description { get; set; }
}

: My Code Snippets | spchol306_ex1_ classes


9. MainPage :
private ListItemCollection _projects;

: My Code Snippets | spchol306_ex1_ property


10. Page InitializeComponent:

39

SharePoint 2010

ClientContext context = new ClientContext(ApplicationContext.Current.Url);


context.Load(context.Web);
List Projects = context.Web.Lists.GetByTitle("Projects");
context.Load(Projects);
CamlQuery query = new Microsoft.SharePoint.Client.CamlQuery();
string camlQueryXml = "<View><Query><Where><Gt>" +
"<FieldRef Name='Due_x0020_Date' />" +
"<Value Type='DateTime'>2008-01-1T00:00:00Z</Value>" +
"</Gt></Where></Query><ViewFields>" +
"<FieldRef Name=\"Title\" /><FieldRef Name=\"Description\" />" +
"<FieldRef Name=\"Due_x0020_Date\" />" +
"</ViewFields></View>";
query.ViewXml = camlQueryXml;
_projects = Projects.GetItems(query);
context.Load(_projects);
context.ExecuteQueryAsync(new
ClientRequestSucceededEventHandler(OnRequestSucceeded), null);

: My Code Snippets | spchol306_ex1_initializecomponent


11. :
private void OnRequestSucceeded(Object sender, ClientRequestSucceededEventArgs
args)
{
// this is not called on the UI thread
Dispatcher.BeginInvoke(BindData);
}
private void BindData()
{
List<Project> projects = new List<Project>();
foreach (ListItem li in _projects)
{
projects.Add(new Project()
{
Title = li["Title"].ToString(),
DueDate = Convert.ToDateTime(li["Due_x0020_Date"].ToString()),
Description = li["Description"].ToString()
});
}
dataGrid1.ItemsSource = projects; // must be on UI thread
}

: My Code Snippets | spchol306_ex1_methods


SharePoint Silverlight
(ClientContext). CAML
, 1 2008 .
Silverlight
DataGrid.

40

SharePoint 2010

3. - SharePoint Silverlight
SharePoint, XAP-, Silverlight,
C:\Program Files\Common Files\Microsoft Shared\Web Server
Extensions\14\TEMPLATE\LAYOUTS\ClientBin.
1. SPSilverlightExample,
.
2. C:\Program Files\Common Files\Microsoft
Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin.

54.

3. . XAP- SharePoint,
- Silverlight - SharePoint.
4. Internet Explorer http://intranet.contoso.com.
5. .
6. -.
7. , - Silverlight .
8. - Silverlight
/_layouts/ClientBin/SPSilverlightExample.xap URL-.

41

SharePoint 2010

55. URL- - Silverlight

9. OK, - Silverlight.
10. .
11. - SharePoint :

56. - Silverlight

Silverlight,
SharePoint . ,
Silverlight SharePoint.

42

SharePoint 2010

4.
SharePoint Silverlight
SharePoint
SharePoint,
LINQ Silverlight .
1. Silverlight
1. Visual Studio 2010, | |
Microsoft Visual Studio 2010 | Microsoft Visual Studio 2010.
2. | | .
3.
| Visual Studio |
.
4. Begin.
5. C:\SPHOLS\SPCHOL306\CS\Ex2\

57.

43

SharePoint 2010

6. OK, .
7. | | .
8.
Visual C# | Silverlight,
Silverlight .
9. SilverlightEmployeeContributionsGraph.
10. .

58.

44

SharePoint 2010

11. OK.

59. Silverlight

12. OK, .
13. SPSilverlightExample
SharePoint Silverlight.
SilverlightEmployeeContributionsGraph .
14. C:\Program Files\Common Files\Microsoft Shared\Web Server
Extensions\14\TEMPLATE\LAYOUTS\ClientBin.
15. Microsoft.SharePoint.ClientSilverlight.dll
Microsoft.SharePoint.Client.Silverlight.Runtime.dll ( CTRL,
).
16. OK, DLL.

45

SharePoint 2010

60.

12. Silverlight Charting Controls. .NET tab


System.Windows.Controls.DataVisualization.Toolkit.

61. DataVisualization

46

SharePoint 2010

2. Employee SharePoint
Silverlight Graph
1. App.xaml
. App.xaml.cs
:
using Microsoft.SharePoint.Client;
using System.Threading;

: My Code Snippets | spchol306_ex2_app_namespaces


2. Application_Startup.
ApplicationContext.Init(e.InitParams, SynchronizationContext.Current);

: My Code Snippets | spchol306_ex2_application_startup


3. XAML MainPage.xaml UserControl
XML:
xmlns:chartingToolkit="clrnamespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Wind
ows.Controls.DataVisualization.Toolkit"

4. Grid Silverlight
:
<chartingToolkit:Chart x:Name="chart" Width="350" Height="250" Title="Team
Contributions">
<chartingToolkit:Chart.Series>
<chartingToolkit:ColumnSeries ItemsSource="{Binding}"
DependentValuePath="Contributions"
IndependentValuePath="Name"
AnimationSequence="FirstToLast"
Title="Contributions" IsSelectionEnabled="True" />
</chartingToolkit:Chart.Series>
</chartingToolkit:Chart>

47

SharePoint 2010

62. XAML Silverlight

5. MainPage.xaml.cs
using:
using Microsoft.SharePoint.Client;

: My Code Snippets | spchol306_ex2_page_namespaces


6. MainPage :
public class EmployeeContributions
{
public string Name { get; set; }
public string TeamName { get; set; }
public decimal Contributions { get; set; }
}
public class TeamContributions
{
public string Name { get; set; }
public decimal Contributions { get; set; }
}

: My Code Snippets | spchol306_ex2_classes


7. MainPage :
private ListItemCollection _employees;

: My Code Snippets | spchol306_ex2_property


8. Page InitializeComponent:
48

SharePoint 2010

ClientContext context = new ClientContext(ApplicationContext.Current.Url);


context.Load(context.Web);
List employees = context.Web.Lists.GetByTitle("Employees");
context.Load(employees);
CamlQuery query = new CamlQuery();
string camlQueryXml = null;
query.ViewXml = camlQueryXml;
_employees = employees.GetItems(query);
context.Load(_employees);
context.ExecuteQueryAsync(new
ClientRequestSucceededEventHandler(OnRequestSucceeded), null);

: My Code Snippets | spchol306_ex2_initializecomponent


9. :
private void OnRequestSucceeded(Object sender, ClientRequestSucceededEventArgs
args)
{
// this is not called on the UI thread
Dispatcher.BeginInvoke(BindData);
}
private void BindData()
{
List<EmployeeContributions> employees = new List<EmployeeContributions>();
// get list item values into a strongly typed class
foreach (ListItem li in _employees)
{
employees.Add(new EmployeeContributions
{
Name = li["Title"].ToString(),
TeamName = li["Team"].ToString(),
Contributions =
Convert.ToDecimal(li["Contribution_x0020__x0028_in_x00"])
});
}
// use linq to group employees on team name and then total team
contributions
List<TeamContributions> teams = employees
.GroupBy(e => e.TeamName)
.Select(t => new TeamContributions
{
Name = t.Key,
Contributions = t.Sum(e => e.Contributions)
}).ToList();
chart.DataContext = teams; // must be on UI thread
}

: My Code Snippets | spchol306_ex2_methods


49

SharePoint 2010

10. , SharePoint
SharePoint Silverlight.
, LINQ
.
.

3. - SharePoint Silverlight

SharePoint, XAP-, Silverlight,


C:\Program Files\Common Files\Microsoft Shared\Web Server
Extensions\14\TEMPLATE\LAYOUTS\ClientBin.
1. SilverlightEmployeeContributionsGraph,
.
2. C:\Program Files\Common Files\Microsoft
Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin.

63. Silverlight

3. . XAP- SharePoint,
- Silverlight - SharePoint.
4. Internet Explorer http://intranet.contoso.com.
50

SharePoint 2010

5. - Silverlight, ,
Silverlight ,
.
- Silverlight -.

64. - Silverlight

6. ( ,
), - Silverlight
/_layouts/ClientBin/SilverlightEmployeeContributionsGraph.xap.

51

SharePoint 2010

65. URL- - Silverlight

7. OK.
8. OK - Silverlight.

52

SharePoint 2010

9. - :

66. - Silverlight

53

SharePoint 2010

5. -
-,
, .
1. -
Silverlight.
1. Visual Studio 2010, | |
Microsoft Visual Studio 2010 | Microsoft Visual Studio 2010.
2. | | .
3.
Visual C# | SharePoint | 2010 |
SharePoint.
4. SBSolutionDemo.
5. C:\SPHOLS\SPCHOL307\CS\Ex1\

67 -

54

SharePoint 2010

6. , .
7. SharePoint ,
, http://intranet.contoso.com/.
8. SharePoint
.

68 - SharePoint ( 1).

9. , . Visual Studio
.
10. SBSolutionDemo
| .
11. , Visual C# | SharePoint | 2010 | .
12. -
SBWebPart.

55

SharePoint 2010

69 -

13. , - .
2. ,
1. SBWebPart.cs using
using:
using System.Web.UI.HtmlControls;

: My Code Snippets | spchol307_ex1_webpart_namespaces


2. SBWebPart :
DropDownList _ddlProjects = new DropDownList();
TextBox _tbDescription = new TextBox();
TextBox _tbDueDate = new TextBox();

: My Code Snippets | spchol307_ex1_webpart_variables


3. SBWebPart :

56

SharePoint 2010

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

: My Code Snippets | spchol307_ex1_webpart_getprojectdetails

57

SharePoint 2010

4. CreateChildControls :
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);
}

: My Code Snippets | spchol307_ex1_webpart_createchildcontrols

58

SharePoint 2010

5. CreateChildControls :
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()));
}
}
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();
}

: My Code Snippets | spchol307_ex1_webpart_populateprojects

3.
- SharePoint.
1. SBSolutionDemo ,
WSP-.
2. Internet Explorer http://intranet.contoso.com.
3. .
4. .

59

SharePoint 2010

70 -

5. .
6. .
7. WSP-,

C:\SPHOLs\SPCHOL307\CS\Ex1\SBSolutionDemo\SBSolutionDemo\bin\Debug\SBSolution
Demo.wsp.
8. , SBSolutionDemo.wsp SharePoint.
.
9.
. - .
10. .
11. -.
.
12. - SBSolutionDemoPage,
, .
.

60

SharePoint 2010

71 - -

13. , -.
14. -
, .
15. -, -,
, SBWebPart.
16. , -
.
17. .

72 - - SBWebPart

61

SharePoint 2010

18.
.
19. andyj, pass@word1.

73 - Windows

20. .
21. - .
.
Internet Explorer.

62

SharePoint 2010

74 - -

63

SharePoint 2010

6.
SharePoint
,
SharePoint,
WSP-.
Visual Studio 2010.
1.
,
SharePoint.
1. Visual Studio 2010, | |
Microsoft Visual Studio 2010 | Microsoft Visual Studio 2010.
2. Visual Studio 2010 , |
| .
3. Visual C# | SharePoint | 2010 | ,
SharePoint.
4. SPCHOL305Ex1,
C:\SPHOLS\SPCHOL305\CS\Ex1.

64

SharePoint 2010

75 -

5. .
6. SharePoint URL- http://intranet.contoso.com
. .

65

SharePoint 2010

76 - SharePoint

7. Visual Studio SPCHOL305Ex1


.
2. ,

1. Visual Studio 2010 , |
| .
2. .NET Framework 3.5

77 - .NET Framework

66

SharePoint 2010

3. Visual C# | |
.
4. SPDActivityDemo .

78 -

5. SPDActivityDemo
.
6. . C:\Program Files\Common
Files\Microsoft Shared\Web Server Extensions\14\ISAPI .
7. Microsoft.SharePoint.dll Microsoft.SharePoint.WorkflowActions.dll
.

67

SharePoint 2010

79 -

8. Activity1.cs
.
9. Activity1.cs CreateDocumentLibrary.cs.

3. ,
,
1.
CreateDocumentLibrary.cs .
2. CreateDocumentLibrary SequenceActivity Activity,
.
public partial class CreateDocumentLibrary : Activity

68

SharePoint 2010

3. A using
using:
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;
using Microsoft.SharePoint.WorkflowActions;

: My Code Snippets | spchol305_ex1_createdoclib_namespace

4. CreateDocumentLibrary DependencyProperty
UrlProperty.

public static DependencyProperty UrlProperty = DependencyProperty.Register("Url",


typeof(string), typeof(CreateDocumentLibrary), new PropertyMetadata(""));
[DescriptionAttribute("Url of base site")]
[BrowsableAttribute(true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible
)]
[ValidationOption(ValidationOption.Optional)]
public string Url
{
get
{
return ((string)(base.GetValue(CreateDocumentLibrary.UrlProperty)));
}
set
{
base.SetValue(CreateDocumentLibrary.UrlProperty, value);
}
}

: My Code Snippets | spchol305_ex1_createdoclib_urlproperty


5. CreateDocumentLibrary DependencyProperty
DocLibNameProperty.

DocumentLibrary,
.

69

SharePoint 2010

public static DependencyProperty DocLibNameProperty =


DependencyProperty.Register("DocLibName", typeof(string),
typeof(CreateDocumentLibrary), new PropertyMetadata(""));
[DescriptionAttribute("Used as doc lib name")]
[BrowsableAttribute(true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible
)]
[ValidationOption(ValidationOption.Optional)]
public string DocLibName
{
get
{
return ((string)(base.GetValue(CreateDocumentLibrary.DocLibNameProperty)));
}
set
{
base.SetValue(CreateDocumentLibrary.DocLibNameProperty, value);
}
}

: My Code Snippets | spchol305_ex1_createdoclib_doclibproperty


6. CreateDocumentLibrary :
protected override ActivityExecutionStatus Execute(ActivityExecutionContext
executionContext)
{
CreateDocLib();
return ActivityExecutionStatus.Closed;
}
private void CreateDocLib()
{
using (SPSite sps = new SPSite(Url))
{
using (SPWeb spw = sps.RootWeb)
{
Guid ID = spw.Lists.Add(DocLibName, DocLibName + " Document Library",
SPListTemplateType.DocumentLibrary);
SPList spdl = spw.Lists[ID];
spdl.OnQuickLaunch = true;
spdl.Update();
}
}
}

: My Code Snippets | spchol305_ex1_createdoclib_execute

70

SharePoint 2010

4. .
1. . SPDActivityDemo.snk Resources
( ) SPDActivityDemo.

80 -

2. SPDActivityDemo
.
3. ,
SPDActivityDemo.snk.

81 -

4. , CTRL-SHIFT-B, .

71

SharePoint 2010

5. SPCHOL305Ex1
SharePoint

82 - SharePoint

6. SharePoint
Template\1033\Workflow .

72

SharePoint 2010

83 - SharePoint

7. Workflow.
8. SPCHOL305Ex1 ( )
.
9. Workflow
| .
10. XML- SPDActivityDemo.ACTIONS,
.

73

SharePoint 2010

84 -

74

SharePoint 2010

7. SPDActivityDemo.ACTIONS :
<?xml version="1.0" encoding="utf-8"?>
<WorkflowInfo>
<Actions Sequential="then" Parallel="and">
<Action Name="Create Document Library"
ClassName="SPDActivityDemo.CreateDocumentLibrary"
Assembly="SPDActivityDemo, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=a66e91d2ee2fa8f8"
AppliesTo="all"
Category="Labs">
<RuleDesigner Sentence="Document Library Name %1 to site %2.">
<FieldBind Field="DocLibName" Text="Document Library Name"
DesignerType="TextArea" Id="1"/>
<FieldBind Field="Url" Text="Url of base site" Id="2"
DesignerType="TextArea"/>
</RuleDesigner>
<Parameters>
<Parameter Name="DocLibName" Type="System.String, mscorlib"
Direction="In" />
<Parameter Name="Url" Type="System.String, mscorlib"
Direction="In" />
</Parameters>
</Action>
</Actions>
</WorkflowInfo>

: My XML Snippets | spchol305_ex1_workflowactions_xml


8. SPDActivityDemo

75

SharePoint 2010

5. SPDActivityDemo,
SPCHOL305Ex1.
1. Package SPCHOL305Ex1.
2. Package.package, .
3. .

85 -

76

SharePoint 2010

4.
.
5.
SPDActivityDemo\bin.

86 -

6. .
:
:
SPDActivityDemo, Version=1.0.0.0, Culture=neutral, PublicKeyToken= a66e91d2ee2fa8f8
: SPDActivityDemo
:
: *
7. ,
, .
8.
77

SharePoint 2010

6.
1. Features
SPCHOL305Ex1 .
2. Feature1
SPCHOL305Ex1Feature.
3. SPCHOL305Ex1Feature
WebApplication.

87 -

7.
1. SPCHOL305Ex1Feature

2. using :
using Microsoft.SharePoint.Administration;

78

SharePoint 2010

3. FeatureReceiver :
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWebApplication wappCurrent = (SPWebApplication)properties.Feature.Parent;
SPWebConfigModification modAuthorizedType = new SPWebConfigModification();
modAuthorizedType.Name = "AuthType";
modAuthorizedType.Owner = "SPDActivityDemo";
modAuthorizedType.Path =
"configuration/System.Workflow.ComponentModel.WorkflowCompiler/authorizedTypes";
modAuthorizedType.Type =
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
modAuthorizedType.Value = "<authorizedType Assembly=\"SPDActivityDemo, "
+ "Version=1.0.0.0, Culture=neutral, PublicKeyToken=a66e91d2ee2fa8f8\" "
+ "Namespace=\"SPDActivityDemo\" TypeName=\"*\" Authorized=\"True\" />";
wappCurrent.WebConfigModifications.Add(modAuthorizedType);
wappCurrent.WebService.ApplyWebConfigModifications();
}

: My code Snippets | spchol305_ex1_spchol305feature_receiver

4. SPCHOL305Ex1Feature,
.

88 -

8.
SharePoint
1. SharePoint Designer 2010, |
| SharePoint | Microsoft SharePoint Designer 2010

79

SharePoint 2010

2. .

89 - SharePoint Designer 2010

:
: Administrator
: pass@word1

80

SharePoint 2010

3. http://intranet.contoso.com

90 -

81

SharePoint 2010

5.
SPDWorkflow, ,
.

91 -

82

SharePoint 2010

6. ,
. : ,
Visual Studio .

92 -

83

SharePoint 2010

7. 1.
Fx.
8. ,
. .

93 -

9. URL- http://intranet.contoso.com.
10. .

94 -

84

SharePoint 2010

11. .
.

95 -

12. .
13.
, .
, WSP-
SharePoint.

96 -

85

SharePoint 2010

14. - http://intranet.contoso.com.
15. ->
-> .

97 -

16. SPDWorkflow
-> .

98 - WSP-

86

SharePoint 2010

17. WSP- ,
( )

99 -

9. Visual Studio
1. Visual Studio 2010,
SPCHOL305Ex1
| .
2. Visual C# | SharePoint | 2010 | ,
.

87

SharePoint 2010

3. SPDWorkflowImport.

100 -

4. .

88

SharePoint 2010

5. , URL- http://intranet.contoso.com. .

101 - SharePoint

89

SharePoint 2010

6. WSP- SPDWorkflow.wsp,
. .

102 - SharePoint

7. .

90

SharePoint 2010

103 - SharePoint

91

SharePoint 2010

8. SPCHOL305Ex1
.

104 - SharePoint

92

SharePoint 2010

9. SPDWorkflowImport
.
10. SPDActivityDemo .

105 -

11. SPDWorkflowImport Workflows\SPDWorkflowFT.


12. Elements.xml.

93

SharePoint 2010

13. SPDWorkflowFT.

106 -

14. , SPCHOL305Ex1.
10. SharePoint
1. http://intranet.contoso.com.
2. |
3. .
4. Customers .
5.

107 -

6. .
7. :
: SPDWorkflowFT
94

SharePoint 2010

108 -

8. .

95

SharePoint 2010

9. Customers |
.

109 -

10. Northwind
.

110 -

96

SharePoint 2010

11. ,
.



SharePoint 2010. , ,
http://msdn.microsoft.com/ru-ru/sharepoint/ee513148.aspx (,
).

97