共用方式為


SharePoint : How to add banner page at the Portal site.

This is everyone's requirement, but unfortunately we do not have any out of box SharePoint functionality. I want to have a banner page at the top and want have a html file content as include directive. Once I modify HTML file at one place then that should get reflected all over the site. But unfortunately include directives can only work in the same application directory. so in sharepoint we cannot have the include directives.

I found an work around to resolve the issue by using the web control.

1. Create a new Web Control Library project in VS. Create a Custom Control (or use
the default one of the project.). Add the following code inside the Render
method:
protected override void Render(HtmlTextWriter output)
{
string sHtml = "";
try
{
string resourceFile = @"C:\Inetpub\wwwroot\header.txt";
System.IO.StreamReader file = System.IO.File.OpenText(resourceFile);
sHtml = file.ReadToEnd() + this.Page.User.Identity.Name;
file.Close();
}
catch(Exception ex)
{
sHtml = "Error : " + ex.Message;
}
output.Write(sHtml);
}
2. Compile the dll and put it into the GAC (Create strong name key file and add the
file path in the AssemblyInfo.cs file)
3. Add the following line in the web.config file of Sharepoint:
<SafeControl Assembly="CustomControl, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=f5b8bf0a7658455a" Namespace="CustomControl" TypeName="*" />
4. Add the following line at the begin of the .aspx template:
<%@ Register Tagprefix="MyControl" Namespace="CustomControl"
Assembly="CustomControl, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=f5b8bf0a7658455a" %>
5. Add the following line at the place to insert the control:
<MyControl:WebCustomControl1 runat="server"/>
6. Create a text file (C:\Inetpub\wwwroot\header.txt) containing the HTML code of
the control