Now our requirement is to create a upload page where "Add as a new
version to existing files" option will be unchecked by default. We don't want to change the upload.aspx file of SharePoint, hence we will create a new custom upload page. To use that custom page, we have to modify the List Template of Document Library. Again we keep away from modifying the original List Template, we need to have our custom List template for document Library.
Here is how we approach:
1.Create a Feature which will install the custom Document Library Template.
2.Create a new control template which renders the New menu, Upload menu, Actions menu and Settings menu in the toolbar
3.To customize the Upload Menu, Create a class which inherits from the Microsoft. SharePoint.WebControls.UploadMenu class and Override the “SetmenuItemProperties” method to navigate to the custom upload page.
4.Create the custom upload page and make changes in it to suit your purpose.
Technical Details:
1. Feature: Copy and rename SharePoint feature for document library and make the only change in schema.xml
2. Create a new control template with the following rendering template.
<SharePoint:RenderingTemplate ID="MyDocumentLibraryViewToolBar" runat="server">
<Template>
<wssuc:ToolBar CssClass="ms-menutoolbar" EnableViewState="false" id="toolBarTbl" ButtonSeparator="<img src='/_layouts/images/blank.gif' alt=''>" RightButtonSeparator=" " runat="server">
<Template_Buttons>
<SharePoint:NewMenu ID="NewMenu1" AccessKey="<%$Resources:wss,tb_NewMenu_AK%>" runat="server"/>
<CustomUpload:DocLibUploadMenu ID="UploadMenu1" AccessKey="<%$Resources:wss,tb_UploadMenu_AK%>" runat="server"/>
<SharePoint:ActionsMenu ID="ActionsMenu1" AccessKey="<%$Resources:wss,tb_ActionsMenu_AK%>" runat="server"/>
<SharePoint:SettingsMenu ID="SettingsMenu1" AccessKey="<%$Resources:wss,tb_SettingsMenu_AK%>" runat="server"/>
</Template_Buttons>
<Template_RightButtons>
<SharePoint:PagingButton runat="server"/>
<SharePoint:ListViewSelector runat="server"/>
</Template_RightButtons>
</wssuc:ToolBar>
</Template>
</SharePoint:RenderingTemplate>
Add Assembly Name and Register Tag prefix of the class we are going to create.
<%@Assembly Name ="MyCustomDocLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ddad7f64566213ec" %>
<%@Register TagPrefix="CustomUpload" Assembly ="MyCustomDocLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ddad7f64566213ec" Namespace="MyCustomDocLib" %>
3. Create a Class File to customize the Upload Menu function.(as refered above CustomUpload:DocLibUploadMenu)
using Microsoft.SharePoint.WebControls;
namespace MyCustomDocLib
{
public class DocLibUploadMenu : UploadMenu
{
protected override void SetMenuItemProperties()
{
if (!DoclibExplorerView)
{
SPListTemplateType type2;
if (base.RenderContext.List.BaseTemplate == SPListTemplateType.WebPageLibrary)
{
this.Visible = false;
return;
}
base.MenuTemplateControl.LargeIconMode = true;
base.MenuControl.MenuFormat = MenuFormat.ArrowSplitButton;
base.MenuControl.HoverCellInActiveCssClass = "ms-splitbutton";
base.MenuControl.HoverCellActiveCssClass = "ms-splitbuttonhover";
string str2 = site.ServerRelativeUrl + "%2F" + SPHttpUtility.UrlKeyValueEncode(base.RenderContext.List.RootFolder.ToString());
string prefixedUrl = WebLayoutsPath + "customupload.aspx?List=" + SPHttpUtility.HtmlEncode(this.List.ID.ToString("B").ToUpper(CultureInfo.InvariantCulture) + "&RootFolder=" + str2 + "&Source=" + SPHttpUtility.HtmlEncode(this.Web.Site.MakeFullUrl(SPUtility.OriginalServerRelativeRequestUrl))) ;//+ "&Myquery=" + item["CustomId"].ToString());
//string prefixedUrl = WebLayoutsPath + "Upload.aspx?List=1234&RootFolder=me&Source=something&MyQuery=its custom";
base.MenuControl.ClientOnClickScript = "STSNavigate('" + SPHttpUtility.EcmaScriptStringLiteralEncode(SPUtility.GetServerRelativeUrlFromPrefixedUrl(prefixedUrl)) + "')";
}
}
}
4.Copy upload.aspx and rename it to customupload.aspx and make changes to suit your purpose.
Get the full code here:
CustomDocLibCode
Here is how we approach:
1.Create a Feature which will install the custom Document Library Template.
2.Create a new control template which renders the New menu, Upload menu, Actions menu and Settings menu in the toolbar
3.To customize the Upload Menu, Create a class which inherits from the Microsoft. SharePoint.WebControls.UploadMenu class and Override the “SetmenuItemProperties” method to navigate to the custom upload page.
4.Create the custom upload page and make changes in it to suit your purpose.
Technical Details:
1. Feature: Copy and rename SharePoint feature for document library and make the only change in schema.xml
View BaseViewID="1" Type="HTML" WebPartZoneID="Main" ToolbarTemplate="MyDocumentLibraryViewToolBar"
<SharePoint:RenderingTemplate ID="MyDocumentLibraryViewToolBar" runat="server">
<Template>
<wssuc:ToolBar CssClass="ms-menutoolbar" EnableViewState="false" id="toolBarTbl" ButtonSeparator="<img src='/_layouts/images/blank.gif' alt=''>" RightButtonSeparator=" " runat="server">
<Template_Buttons>
<SharePoint:NewMenu ID="NewMenu1" AccessKey="<%$Resources:wss,tb_NewMenu_AK%>" runat="server"/>
<CustomUpload:DocLibUploadMenu ID="UploadMenu1" AccessKey="<%$Resources:wss,tb_UploadMenu_AK%>" runat="server"/>
<SharePoint:ActionsMenu ID="ActionsMenu1" AccessKey="<%$Resources:wss,tb_ActionsMenu_AK%>" runat="server"/>
<SharePoint:SettingsMenu ID="SettingsMenu1" AccessKey="<%$Resources:wss,tb_SettingsMenu_AK%>" runat="server"/>
</Template_Buttons>
<Template_RightButtons>
<SharePoint:PagingButton runat="server"/>
<SharePoint:ListViewSelector runat="server"/>
</Template_RightButtons>
</wssuc:ToolBar>
</Template>
</SharePoint:RenderingTemplate>
Add Assembly Name and Register Tag prefix of the class we are going to create.
<%@Assembly Name ="MyCustomDocLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ddad7f64566213ec" %>
<%@Register TagPrefix="CustomUpload" Assembly ="MyCustomDocLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ddad7f64566213ec" Namespace="MyCustomDocLib" %>
3. Create a Class File to customize the Upload Menu function.(as refered above CustomUpload:DocLibUploadMenu)
using Microsoft.SharePoint.WebControls;
namespace MyCustomDocLib
{
public class DocLibUploadMenu : UploadMenu
{
protected override void SetMenuItemProperties()
{
if (!DoclibExplorerView)
{
SPListTemplateType type2;
if (base.RenderContext.List.BaseTemplate == SPListTemplateType.WebPageLibrary)
{
this.Visible = false;
return;
}
base.MenuTemplateControl.LargeIconMode = true;
base.MenuControl.MenuFormat = MenuFormat.ArrowSplitButton;
base.MenuControl.HoverCellInActiveCssClass = "ms-splitbutton";
base.MenuControl.HoverCellActiveCssClass = "ms-splitbuttonhover";
string str2 = site.ServerRelativeUrl + "%2F" + SPHttpUtility.UrlKeyValueEncode(base.RenderContext.List.RootFolder.ToString());
string prefixedUrl = WebLayoutsPath + "customupload.aspx?List=" + SPHttpUtility.HtmlEncode(this.List.ID.ToString("B").ToUpper(CultureInfo.InvariantCulture) + "&RootFolder=" + str2 + "&Source=" + SPHttpUtility.HtmlEncode(this.Web.Site.MakeFullUrl(SPUtility.OriginalServerRelativeRequestUrl))) ;//+ "&Myquery=" + item["CustomId"].ToString());
//string prefixedUrl = WebLayoutsPath + "Upload.aspx?List=1234&RootFolder=me&Source=something&MyQuery=its custom";
base.MenuControl.ClientOnClickScript = "STSNavigate('" + SPHttpUtility.EcmaScriptStringLiteralEncode(SPUtility.GetServerRelativeUrlFromPrefixedUrl(prefixedUrl)) + "')";
}
}
}
4.Copy upload.aspx and rename it to customupload.aspx and make changes to suit your purpose.
Get the full code here:
CustomDocLibCode
