2008年12月23日 星期二
Where is Microsoft.SharePoint.Publishing?
How to write sever-side code in sharepoint master page
Yes,we know we can add server-side code in asp.net master page directly.
However,when I want to add sever-side code in shaerpoint's master page,
there's unknow error occur.You can't add any server-side code in every
sharepoint page.
If you want to add code in sharepoint master page by code-inline, you can add
code by these steps as folloes:
1.add section in web.config:
<PageParserPaths>
<PageParserPath VirtualPath="/_catalogs/masterpage/*" CompilationMode="Always"
AllowServerSideScript="true" IncludeSubFolders="true" />
</PageParserPaths>
2.And you can add sever-side code in your master page,like this:
<script runat="server">
string myVar = "hello world!";
void Page_Load(object sender, System.EventArgs e)
{
Response.Write(myVar);
SPSite siteCollection = new SPSite("http://usb-server1");
SPWeb site = siteCollection.OpenWeb("/SiteDirectory/MainCalendar/");
SPList list = site.Lists["Announcements"];
SPListItemCollection items = list.Items;
foreach(SPListItem item in items)
{
Response.Write(item["Title"].ToString());
Response.Write("<br/>");
}
}
</script>
code behide:
Create a class and compile it. import your class namespace in your sharepoint
master page.
reference link:
MSDN
2008年12月3日 星期三
How to use custom master page that in master gallery in application page.
Therefore, you can't use master page in master page gallery.
If you want to use master page gallery's master page,
you should define your master page in OnPreInit event.
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
SPWeb Web = SPContext.Current.Web;
string strUrl =
Web.ServerRelativeUrl + "/_catalogs/masterpage/default.master";
this.MasterPageFile = strUrl;
}
Please refence MSDN:http://msdn.microsoft.com/en-us/library/cc297200.aspx