SharePoint Online에서의 비쥬얼 웹 파트(Visual Web Part)
SharePoint Online에서의 비쥬얼 웹 파트(Visual Web Part)
Office 365의 SharePoint Online에서는 샌드박스 솔루션을 지원하고 Farm 솔루션에 대한 부분은 제한적이라 특히 비쥬얼 웹 파트(Visual Web Part)를 지원하지 않아 웹 파트 개발에 제한적인 측면이 있는 것이 사실입니다.
하지만 Visual Studio 2010 SharePoint Power Tools 을 통해서는 극복이 가능합니다. SharePoint Online에 Sandboxed 솔루션에서 비쥬얼 웹 파트(Visual Web Part) 를 구현 할 수 있습니다.
Visual Studio 2010 SharePoint Power Tools 은 아래 링크를 통해 다운로드 가능합니다.
http://visualstudiogallery.msdn.microsoft.com/8e602a8c-6714-4549-9e95-f3700344b0d9/
SharePoint 프로젝트에서 새 항목을 추가할 때 아래그림처럼 Visual Web Part(Sandboxed) 를 볼 수 있으며 이를 통해 SharePoint Online에서 비쥬얼 웹 파트(Visual Web Part)를 통해 솔루션을 개발 할 수 있습니다.
아래 그림처럼 서버 컨트롤을 추가하여 디자인 화면을 구성하였습니다. 샌드박스 솔루션으로요~
아래와 같은 메서드를 Page_Load 이벤트에 적용합니다.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
GetList();
}
}
private void GetList()
{
SPWeb web = SPContext.Current.Web;
var ListNames = from SPList list in web.Lists
where list.BaseTemplate !=
SPListTemplateType.DocumentLibrary
select list.Title;
ddlLists.DataSource = ListNames;
ddlLists.DataBind();
}
DropDownList의 SelectedIndexChanged 이벤트에 아래와 같은 코드로 데이터를 DataGrid에 나타냅니다.
private void GetListData()
{
SPList SourceList = SPContext.Current.Web.Lists.TryGetList(ddlLists.SelectedValue);
SPQuery qry = new SPQuery();
qry.ViewFieldsOnly = true;
qry.ViewFields = "<FieldRef Name='Title' /><FieldRef Name='Author' />";
qry.RowLimit = 20;
gridListItems.DataSource = SourceList.GetItems(qry).GetDataTable();
gridListItems.EmptyDataText =
string.Format(
"The {0} list does not contain any items!",
SourceList.Title);
gridListItems.DataBind();
}
샌드박스 솔루션을 SharePoint Online에 배포하고 난 후 결과는 아래와 같습니다. SharePoint Online에서도 리소스 범위 내에서 비쥬얼 웹 파트(Visual Web Part)가 잘 동작되는 것을 확인할 수 있습니다.
모든 컨트롤이 지원되는 것은 아닙니다. Visual Studio 2010 SharePoint Power Tools을 통해 샌드박스 솔루션에서 컴파일을 하면 문제가 되는 것은 사전에 오류가 발생하는 것을 알 수 있습니다.