You are on page 1of 7

I HC CNG NGHIP TP.

HCM

KHOA CNG NGH THNG TIN

BI TP THC HNH
PHN 0 : LM QUEN VI LP TRNH TRONG SHAREPOINT 1. To mi mt FEATURE _ Khi to mt Class Library DLL project (Vd: c tn HelloWorld) . _ To th mc TEMPLATE\FEATURES\<Tn Project> _ To 2 file : feature.xml v elements.xml + feature.xml <Feature Id=To ID cho feature Title=Tn feature Description=M t cho feature Scope=Web Hidden=FALSE ImageUrl=ng dn hnh i din xmlns=http://schemas.microsoft.com/sharepoint/> <ElementManifests> <ElementManifest Location=elements.xml /> </ElementManifests> </Feature> + elements.xml <Elements xmlns=http://schemas.microsoft.com/sharepoint/> <CustomAction Id=SiteActionsToolbar GroupId=SiteActions Location=Microsoft.SharePoint.StandardMenu Sequence=100 Title=Hello World Description=M t cho feature ImageUrl=ng dn ti hnh i din> <UrlAction Url=http://msdn.microsoft.com /> </CustomAction> </Elements> _ To file install.bat tin hnh ci t feature vo trong SharePoint bng cch s dng STSADM.EXE @SET TEMPLATEDIR=ng dn ti th mc TEMPLATE @SET STSADM=ng dn ti file stsadm.exe Echo Copying files Xcopy /e /y TEMPLATE\* %TEMPLATEDIR% CC K THUT INTERNET NNG CAO NG THANH MINH

force

Echo Installing feature %STSADM% -o InstallFeature filename <Tn Project>\feature.xml

Echo Restart IIS Worker Process IISRESET _ Right click ln Project v chn Properties, chn Post-build event v thm vo cc dng sau : cd $(ProjectDir) Install.bat 2. Thm s kin cho feature . (To ging bi trn) _ Thm Microsoft.SharePoint.dll vo trong project . _ i tn Class1.cs thnh FeatureReceiver.cs _ Cho class FeatureReceiver k tha SPFeatureReceiver _ Override cc hm : FeatureInstalled, FeatureUninstalling, FeatureActivated, FeatureDeactivating . _ Ti hm FeatureActivated thm : SPWeb site = (SPWeb)properties.Feature.Parent; site.Properties[OriginalTitle] = site.Title; site.Properties.Update(); site.Title = Tn project; site.Update(); _ Ti hm FeatureDeactivating thm : SPWeb site = (SPWeb)properties.Feature.Parent; site.Title = site.Properties[OriginalTitle]; site.Update(); _ Thit lp thm 2 thuc tnh ReceiverAssembly v ReceiverClass trong feature.xml ReceiverAssembly=<Tn project>, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b59ad8f489c4a334 ReceiverClass=<Tn project>.<Tn class> 3. To trang custom application trong sharepoint _ To class CustomApplicationPages ging cc bc trn . _ Trong th mc TEMPLATE, to thm th mc LAYOUTS\CustomApplicationPages _ To trang ApplicationPage1.aspx (vit code inline)
<%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Page Language="C#" MasterPageFile="~/_layouts/application.master" Inherits="Microsoft.SharePoint.WebControls.LayoutsPageBase" %> <%@ Import Namespace="Microsoft.SharePoint" %> <script runat="server"> protected override void OnLoad(EventArgs e) { SPWeb site = this.Web; lblSiteTitle.Text = site.Title; lblSiteID.Text = site.ID.ToString().ToUpper(); } </script>

CC K THUT INTERNET NNG CAO

NG THANH MINH

<asp:Content ID="Main" contentplaceholderid="PlaceHolderMain" runat="server"> <table border="1" cellpadding="4" cellspacing="0" style="font-size:12"> <tr> <td>Site Title:</td> <td><asp:Label ID="lblSiteTitle" runat="server" /></td> </tr> <tr> <td>Site ID:</td> <td><asp:Label ID="lblSiteID" runat="server" /></td> </tr> </table> </asp:Content> <asp:Content ID="PageTitle" contentplaceholderid="PlaceHolderPageTitle" runat="server"> Hello World </asp:Content> <asp:Content ID="PageTitleInTitleArea" runat="server" contentplaceholderid="PlaceHolderPageTitleInTitleArea" > The Quintessential 'Hello World' of Application Page </asp:Content>

_ To trang ApplicationPage2.aspx (Vit code behind)


<%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Assembly Name="CustomApplicationPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ae3824888e1d5225" %> <%@ Page Language="C#" MasterPageFile="~/_layouts/application.master" Inherits="CustomApplicationPages.ApplicationPage2" EnableViewState="false" EnableViewStateMac="false" %> <%@ Import Namespace="Microsoft.SharePoint" %> <asp:Content ID="Main" contentplaceholderid="PlaceHolderMain" runat="server"> <table border="1" cellpadding="4" cellspacing="0" style="font-size:12"> <tr> <td>Site Title:</td> <td><asp:Label ID="lblSiteTitle" runat="server" /></td> </tr> <tr> <td>Site ID:</td> <td><asp:Label ID="lblSiteID" runat="server" /></td> </tr> </table> </asp:Content> <asp:Content ID="PageTitle" contentplaceholderid="PlaceHolderPageTitle" runat="server"> Hello World </asp:Content> <asp:Content ID="PageTitleInTitleArea" runat="server" contentplaceholderid="PlaceHolderPageTitleInTitleArea" > Application Page 2: 'Hello World' with code behind </asp:Content>

_ To file ApplicationPage2.cs
using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Microsoft.SharePoint; using Microsoft.SharePoint.WebControls; namespace CustomApplicationPages { public class ApplicationPage2:LayoutsPageBase

CC K THUT INTERNET NNG CAO

NG THANH MINH

{ protected Label lblSiteTitle; protected Label lblSiteID; protected override void OnLoad(EventArgs e) { SPSite siteCollection = this.Site; SPWeb site = this.Web; lblSiteTitle.Text = site.Title; lblSiteID.Text = site.ID.ToString().ToUpper(); } } }

_ Trong file elements.xml ta thm on code sau :


<Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <!-- Add Command to Site Actions Dropdown --> <CustomAction Id="HelloApplicationPage" GroupId="SiteActions" Location="Microsoft.SharePoint.StandardMenu" Sequence="2000" Title=" Application Page 1" Description="Getting up and going with inline code"> <UrlAction Url="~site/_layouts/CustomApplicationPages/ ApplicationPage1.aspx"/> </CustomAction> <!-- Add Command to Site Actions Dropdown --> <CustomAction Id="CustomApplicationPage1" GroupId="SiteActions" Location="Microsoft.SharePoint.StandardMenu" Sequence="2001" Title="Application Page 2" Description="Moving to code behind"> <UrlAction Url="~site/_layouts/CustomApplicationPages/ApplicationPage2.aspx"/> </CustomAction> </Elements>

PHN 1 : TM HIU WEB PART V CC PHNG THC 1. Vit Web Part trnh by chui Hello Word! trn trang .aspx v trong vng ca Web part. 2. Vit Web Part trnh by thi gian thc hin trong mi phng thc nh: CreateChildControl, OnPreRender, OnLoad 3. Vit Web Part trnh by giao din ca trang ng k ngi dng vi hu ht cc iu khin . PHN 2 : TM HIU ASP.NET SERVER CONTROL TRONG WEB PART 1. Thm danh sch phn t vo iu khin DropDownList v ListBox. 2. Mi khi ngi s dng chn gi tr trn hai u khin ny th in ra gi tr chn trn iu khin vo Label hay Literal. 3. To Web Part dng ng nhp, cho php chn vo hai tu chn SharePoint List hay SQL Server. Nu ngi s dng chn vo SQL Server th bn trnh by khung cho php s dng nhp Server Name, Database Name, User Name v Password; ngc li th cho php nhp tn List. Lu : Tt c gi tr trong bi tp ny l hard code v vit trn server side

CC K THUT INTERNET NNG CAO

NG THANH MINH

//Tm hiu v cc validation 4.Thit k trang Web Part, bao gm email, password v nt OK, bn ch cho php ngi s dng submit v server khi nhp email hp l v password khng rng. 5.Thit k Web part trnh by tp d liu t i tng DataTable cha danh sch ngi s dng bao gm m, tn sinh vin bng iu khin DataGrid; trn iu khin iu khin DataGrid bn cho php ngi s dng nhp im sinh vin (0 n 10). Khi ngi s dng nhn nt Save, bn in ra danh sch sinh vin vi s im nhp vo. 6.Thit k trang Web Part, bao gm email, password, nt OK v nt Cancel, bn ch cho php ngi s dng submit v server khi nhp email hp l v password khng rng. Khi ngi s dng nhn nt Cancel th d liu nhp trn email, password s b xo. PHN 3 : TM HIU KHAI BO V S DNG THUC TNH 1. Thit k trang Web Part, bao gm thuc tnh tn v m ca List, mc nh ca hai thuc tnh ny l rng, sau khi ngi s dng nhp tn v m vo TextBox v nhn nt Save. Ln sau bn m li trang Web th TextBox s trnh by ga tr ca thuc tnh ca ln lu cui cng. 2.Thit k Web part, bao gm thuc tnh tn v m ca List, mc nh ca hai thuc tnh ny l rng, cho php ngi s dng nhp ga tr cho hai thuc tnh ny trong ToolPart ca SharePoint. 3.Thit k Web Part cho php lit k tt c cc thuc tnh ca List ra mn hnh. PHN 4 : LIN H GIA TOOLPART V WEBPART 1.Thit k Web part, bao gm thuc tnh tn v m ca List, mc nh ca hai thuc tnh ny l rng, cho php ngi s dng nhp ga tr cho hai thuc tnh ny trong ToolPart do bn khai bo bng hai iu khin TextBox. 2.Tip theo cu trn, bn khai bo phng thc cho php in ga tr ca thuc tnh vo hai iu khin TextBox trong ToolPart. 3.Thit k Web part, bao gm thuc tnh tn v m ca List, mc nh ca hai thuc tnh ny l rng, cho php ngi s dng chn ga tr cho hai thuc tnh ny trong ToolPart do bn khai bo bng hai iu khin DropDownList. Mi khi ngi s dng kch hot ToolPart, bn phi chn ga tr trn hai iu khin DropDownList ng vi ga tr ca hai thuc tnh. PHN 5 : LM VIC VI SPWEB V SPCONTROL 1.Vit Web part cho php lit k danh sch Site Template ca Site hin hnh trn DropDownList, mi khi ngi s dng chn Site Template th in ra ID v Name trn iu khin Literal. 2.Vit Web part cho php lit k danh sch Web part ca Site hin hnh trn DropDownList ca Site, mi khi ngi s dng chn Web part th in ra thng tin trn iu khin Literal. CC K THUT INTERNET NNG CAO NG THANH MINH

3.Vit Web part cho php ngi s dng cung cp cc thng tin cn thit to mt Site. PHN 6 : LM VIC VI USER V GROUP 1.Vit Web part cho php lit k danh sch Group ca Site hin hnh trn DropDownList ca Site, mi khi ngi s dng chn Group th in ra thng tin ca Group ny trn iu khin Literal. 2.Vit Web part cho php lit k danh sch Group ca Site hin hnh trn DropDownList ca Site, mi khi ngi s dng chn Group th in ra danh sch ngi s dng trn iu khin DropDownList khc. 3.Vit Tool part cho php ngi dng s dng c Web part nu Group ca h c chn trong ToolPart. V d, nu Administrator chn Contributor th nhng ngi s dng thuc nhm ny c th s dng c Web part (ch cn c nt OK). PHN 6 : LM VIC VI LIST V VIEW 1.Thit k Web part, bao gm thuc tnh tn v m ca List, mc nh ca hai thuc tnh ny l rng, cho php ngi s dng chn ga tr cho hai thuc tnh ny trong ToolPart do bn khai bo bng iu khin DropDownList. Mi khi ngi s dng kch hot ToolPart, bn phi chn ga tr trn hai iu khin DropDownList ng vi ga tr ca hai thuc tnh. 2.Thit k Web part, bao gm thuc tnh tn v m ca List; thuc tnh tn v m ca View; mc nh ca 4 thuc tnh ny l rng, cho php ngi s dng chn ga tr ca List ny trong ToolPart (do bn khai bo bng iu khin DropDownList). Mi khi ngi s dng thay i List th danh sch View ca List s cp nht vo iu khin DropDownList th hai. Khi ngi s dng kch hot ToolPart, bn phi chn ga tr trn hai iu khin DropDownList ng vi ga tr ca hai thuc tnh List v View. 3.Vit Web Part cho php trnh by d liu ca List chn trong ToolPart, bn cn kim tra List nu chng b xo v t mi tr li cng tn (m rng Web Part ny cho trng hp View, Field tn ti trong List hay khng)? 4.Thit k Web part cho php ngi s dng chn List, sau lit k danh sch cc List khc c ct Lookup vo iu khin DropDownList th hai. 5.Thit k Web part cho php to ra List v View mc nh ca n khi ngi s dng nhn nt Create. 6.Vit WebPart cho php t ng to List vi cu trc no khi ngi s dng ko WebPart vo trang ASP.NET ca SP 7.Vit WebPart cho php trnh by danh sch ContentType ca List trong MOSS2007 PHN 7 : KHM PH FIELD V DATATYPE 1.Thit k Web part cho php ngi s dng lit k danh sch field v kiu d liu ca chng thuc List c chn trong ToolPart.

CC K THUT INTERNET NNG CAO

NG THANH MINH

2.Thit k Web part cho php ngi s dng lit k danh sch field v ga tr mc nh cng vi cc thuc tnh khc ca List chn trong Toolpart. 3.Thit k Web part hin cc ASP.NET Control ng vi kiu d liu cho php ngi s dng nhp d liu tng ng. PHN 8 : LM VIC VI WEB PART CONNECTION 1. Vit Web part cho php ci t Web Part Connection trn thc n khi chn ch Modify Shared Web Part 2.Tip theo Web part trn, bn ci t radio button trn mi item ca Web part, mi khi ngi s dng chn vo radio button, web part c kt ni s trnh by d liu theo item bn chn. PHN 9 : LM VIC VI ASP.NET CONTROLS VI LIST V VIEW 1. Vit Web Part cho php trnh by danh sch item trn iu khin DataGrid t List cho trc v cho php ngi s dng sp xp chng theo header 2.Vit Web Part cho php trnh by danh sch item trn iu khin DataGrid t View cho trc v cho php ngi s dng phn trang 3. Khai bo Tool part lit k danh sch cc Field trong View trn iu khin ListBox th nht ri cho php ngi s dng chn tng Item v thm vo iu khin ListBox th hai. 4.Vit Tool Part cho php trnh by phn ng nhp ca SQL Server v SharePoint. Nu ngi s dng chon SharePoint th bn lit k danh sch List trn iu khin DropDownList th nht, khi chn tip tn List th bn lit k danh sch View trn iu khin DropDownList th hai. i vi trng hp SQL Server th bn yu cu ngi s dng ng nhp theo hai hnh thc Windows Authenticate or SQL Server Authenticate, mi khi ng nhp thnh cng bn lit k danh sch Table trn iu khin DropDownList th nht .

CC K THUT INTERNET NNG CAO

NG THANH MINH

You might also like