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
2008年11月18日 星期二
Using Javascript in master page
How to use comstomizable javascipt file in master page?
You should put your js to C:\program files\common files\Microsoft shared\web server extensions\12\Template\layouts
and use code as follows:
<sharepoint:scriptlink language="javascript" name="../YourFolder in layouts/YourJS.js" runat="server"≯
2008年10月22日 星期三
How to delete closed webpart.
There is a resource hog waiting to be released in your SharePoint environment… when a web part is added to a page in SharePoint and subsequently "closed" by the user at a later date, the end user will most often believe the web part to be deleted.
Let's think about why the end user believes the web part is deleted:
- The user most likely clicked the "x" button on the web part when editing the page (site actions > edit page).
- The tool tip on the "x" button says "close
"
Everything the user has done is standard practice for deleting/removing items in a Windows environment.
The Hidden SharePoint Resource Hog
In reality, the web part still lives on the page in a hidden state silently consuming server resources every time the page is accessed. What the user has done is known as "closing" a web part.
What happens if the user wants to add the same web part at a later date? They will most likely do what they were taught in the first place: Site Actions > Edit Page: Add a Web Part > And then select and re-configure the same web part.
What happens if the user repeats this cycle of closing/creating the same web part? The same web part will now live in multiple instances on the same web page. And over time this can become a fairly large resource hog.
Properly Deleting a Web Part
To properly delete a web part, the user should not user the "x" icon when editing the web part. Rather, they should use:
- Site Actions > Edit Page: Find the web part in question and click: edit > delete (see screen shot):
Re-Opening a Closed Web Part
To re-open a closed web part:
- Site Actions > Edit Page:
- Add a web part
- Advanced Web part gallery and options
- Select "Closed Web Parts"
- Drag-n-drop the web part back onto your page
Managing Web Parts
An easy way to manage all the web parts on a page is to simply append a given URL with the parameter: contents=1. For example:
http://moss/sites/marketing/default.aspx will become:
http://moss/sites/marketing/default.aspx?contents=1
Voila! You are now on the Web Part Page Maintenance:
Note: If a web part is closed on a page (Open on page? = no), then using the "Reset" action will not restore the web part to the page. Rather, it will "reset" the web part to its default values. You need to use the steps described above to re-open the web part.
Other Thoughts
I can understand why the SharePoint developers decided to close, rather than delete a web part when clicking the "x" button as it allows the user to hide the web part and then show it again at a later date without requiring any re-configuration. However, the SharePoint developers should have chosen an icon other than the "x" as this only leads to confusion.