私はSharepoint 2010のビジュアルWebパーツを作成するのが初めてで、実際にVisual Studioで新しいビジュアルWebパーツを作成して、SharePointプロジェクトの「人とグループの列」の数を取得しようとしています. これをウェブで見つけて、自分のプロジェクトに合うように値を編集しました。ただし、システムは「名前 'SPContext' は現在のコンテキストに存在しません」というエラーを表示し続けます。
ここに私のコードがあります:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
namespace CountingNoOfAttendee.VisualWebPart1
{
public partial class VisualWebPart1UserControl : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
base.OnInit(e);
display1 = new Label();
}
protected override void CreateChildControls()
{
Controls.Add(display1);
try
{
var list = SPContext.Current.Web.Lists.TryGetList("Register training");
var items = list.Items;
foreach (SPListItem item in items)
{
var userColumn = item["Attendees"];
var users = userColumn as SPFieldUserValueCollection;
display1.Text = string.Format(display1.Text.Title,(users == null?0 : users.Count));
}
}
catch (Exception e)
{
display1.Text = string.Format("An error occurred:", e.Message);
}
base.CreateChildControls();
}
}
}
助けていただければ幸いです。