Skip to main content
SharePoint

SharePoint Team Blog

SharePoint, MOSS RSS Feed
Go Search
Nanmu
SharePoint Team
Team Workspace
Team Blog
SharePoint Blog
SharePoint 2010
Membership
Leave Word
  

SharePoint Team Workspace > SharePoint Team Blog
SharePoint, SharePoint Team Blog
SharePoint & MOSS Customizing the List Toolbar Template (Reship)

SharePoint Rendering Templates

All the rendering Templates for the List are defined in the defaulttemplates.ascx in the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES folder.

This defaulttemplates.ascx control defines the toolbar controls and the form controls for every list template.

The following table explains the rendering template Id and the respective List templates it associated with. Few examples of rendering template have been taken in this table:

                   Rendering Template

                   List Template

ViewToolbar

Custom List, Tasks List,

DocumentLibraryViewToolBar

Document Library

WikiLibraryViewToolBar

Wiki Library

WebPartGalleryViewToolBar

Web Part Gallery List

PictureLibraryViewToolBar

Picture Library List

SiteListGalleryViewToolBar

Site List Gallery

 

These rendering templates have been associated with the List template through the schema.xml file of the list definition.

All the OOB SharePoint List definitions are created as a feature. Each definition has a schema.xml file which defines the Fields and Views of the list. In the Views you can set the “ToolbarTemplate” property to select the template from the defaulttemplates.ascx.

In this blog will walk through you on customizing the toolbar of the document library.

Customizing the toolbar of the document library template

So far it’s clear that the rendering template in the defaulttemplates.ascx renders the controls for the toolbar for every list in the SharePoint. For document library the rendering template is “DocumnetLibraryViewToolbar”. Following is the snippet of “DocumentLibraryViewToolbar” from the defaulttemplates.ascx.

<SharePoint:RenderingTemplate ID="DocumentLibraryViewToolBar" runat="server">

      <Template>

            <wssuc:ToolBar CssClass="ms-menutoolbar" EnableViewState="false" id="toolBarTbl" ButtonSeparator="<img src='/_layouts/images/blank.gif' alt=''>" RightButtonSeparator="&nbsp;&nbsp;" runat="server">

                  <Template_Buttons>

                        <SharePoint:NewMenu AccessKey="<%$Resources:wss,tb_NewMenu_AK%>" runat="server"/>

                        <SharePoint:UploadMenu AccessKey="<%$Resources:wss,tb_UploadMenu_AK%>" runat="server"/>

                        <SharePoint:ActionsMenu AccessKey="<%$Resources:wss,tb_ActionsMenu_AK%>" runat="server"/>

                        <SharePoint:SettingsMenu 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>

 

The gray shaded part in the above code shows the SharePoint controls rendered for the toolbar through this template. The New, Upload, Action and Settings are the menu control rendered in the left part of the toolbar. The ListViewSelector is the view selector control rendered in the right of the toolbar.

If you want to customize this toolbar then you need to create your custom rendering template in the defaulttemplates.ascx control. Consider you want to customize toolbar in such a way that you want to restrict the user from uploading document and just want them to create the document from the SharePoint server. To achieve this you need to create a rendering template without upload menu in the defaulttemplates.ascx and need to associate this template with the schema.xml of the list definition by setting the “ToolbarTemplate” view property.

 

Modifying the OOB files are not supported so you need to create a customdefaulttemplates.ascx to add the rendering template without upload menu and you need to create a custom document library definition to associate the toolbar template with the definition.

Following are the steps to customize the toolbar template in the supported way.

      

1.   Copy the defaulttemplates.ascx and place it in the same location C:\Program Files\Common Files\Microsoft      Shared\webserverextensions\12\TEMPLATE\CONTROLTEMPLATES. You can give any custom name to the ascx file.

2.   Remove all the rendering templates from the custom defaulttemplates.ascx except the “DocumentLibraryViewToolbar”. Change the ID to any custom name say “CustomDocumentLibraryViewToolbar”.

 

3.   Remove the “SharePoint: UploadMenu” control rendering from the template and save the custom defaulttemplates.ascx. The resultant rendering template looks like follows:

 

<SharePoint:RenderingTemplate ID="CustomDocumentLibraryViewToolBar" runat="server">

      <Template>

            <wssuc:ToolBar CssClass="ms-menutoolbar" EnableViewState="false" id="toolBarTbl" ButtonSeparator="<img src='/_layouts/images/blank.gif' alt=''>" RightButtonSeparator="&nbsp;&nbsp;" runat="server">

                  <Template_Buttons>

                        <SharePoint:NewMenu AccessKey="<%$Resources:wss,tb_NewMenu_AK%>" runat="server"/>                                      <SharePoint:ActionsMenu AccessKey="<%$Resources:wss,tb_ActionsMenu_AK%>" runat="server"/>

                        <SharePoint:SettingsMenu 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>

 

4.  Create a custom document library definition. To create a custom document library definition copy the “DocumentLibrary” folder from C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES and paste in the same location with a custom name.

5.  Change the feature Id of the custom document library definition in the feature.xml file. Change the Title, Description and other property you want to modify.

6.  Open the schema.xml file of your custom document library definition and in the default view (BaseViewId=1) add the “ToolbarTemplate” attribute which mentions your custom rendering template created without the upload menu. The code snippet looks like follows :

 

<View BaseViewID="1" Type="HTML" WebPartZoneID="Main" ToolbarTemplate="CustomDocumentLibraryViewToolBar"  DisplayName="$Resources:core,All_Documents;" DefaultView="TRUE" MobileView="True" MobileDefaultView="True" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/dlicon.png" Url="Forms/AllItems.aspx"><!-- _locID@DisplayName="camlidDc1" _locComment=" " -->

7.  Save the schema.xml file. Do an IISRESET. Install and activate the custom document library definition feature through stsadm command.

8.  Now the custom document library definition will be available in the gallery while you create a dcumnet library. Select the custom document library and create the document library in the sharepoint site.

9.  Now you can notice that the document library toolbar doesn’t have the “Upload Menu” in it.

 

Further, If you want to override any of the functionality of this control. Then you can create a class library inheriting this control and ovverride the property you are looking for. Then add your DLL reference in the custom defaulttemplates.ascx and render the custom control instead of the OOB controls in the toolbar rendering template. 

                      HAPPY CUSTOMIZING.

Reship:Hide user accounts in Windows 7

[Reship]

Many times it is convenient to create a special administrator account that can be used for the task scheduler.

Unfortunately, if your Windows 7 computer is not joined to a domain, any accounts you create are shown at the start-up screen:

It would look better if you could remove this special account from the welcome screen, and only show real user accounts.

How can you remove this from the welcome screen?

Well, it happens that there is a registry key that will allow you to do this. Before I start to tell you what it is – I want to give you a word of warning:

Hide the wrong account, and you could lock yourself out forever. If you hose your system, don't come crying to me

Ok, now that we got that out of the way, open regedit and drill down to:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows
NT\CurrentVersion\Winlogon\

Under this key, you will need to create two sub keys. First create a key named "SpecialAccounts", and under that key create another named "UserList".

The final registry path will look like this:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows
NT\CurrentVersion\Winlogon\SpecialAccounts\UserList

It is possible those keys already exist, and if they do then, hey, you get to skip a step

Next you need to create a new DWORD value under that key.

The value name is the exact username that you want to hide.

The numerical value is a 0 or a 1. If you set it to 0, then the account will be hidden. Set it to 1, and it will be shown.

You can see here that I have created a value for my SchedAccount:

After closing regedit, and switching back to the welcome screen we can see that the SchedAccount is no longer displayed:

This is a simple and fast way to hide an account, but at the same time please be very careful.

To drive home the point – look at the UAC prompt when I disabled all accounts, except a limited user account:

That YES button looks really clickable doesnt it? Yea right, now were stuck. No way of ever getting admin rights on the system again. Once you are in this state, you will need to restore from backup. So check twice before making those registry changes.

SharePoint CAML compare expressions
Field Name="Reference" DisplayName="Reference" Type="Computed"> 
 
<FieldRefs> 
 
<FieldRef Name="ID"/> 
 
<FieldRef Name="Prefix"/> 
 
</FieldRefs> 
 
<DisplayPattern> 
 
<Column Name="Prefix"/> 
 
<HTML><![CDATA[-]]></HTML> 
 
<IfEqual> 
 
<Expr1> 
 
<Gt> 
 
<Column Name="ID" /> 
 
<Value Type="Integer">10</Value> 
 
</Gt> 
 
</Expr1> 
 
<Expr2>TRUE</Expr2> 
 
<Then><HTML><![CDATA[0]]></HTML></Then> 
 
<Else><HTML><![CDATA[00]]></HTML></Else> 
 
</IfEqual> 
 
<Column Name="ID"/> 
 
</DisplayPattern> 
 
</Field> 
SharePoint CAML Key words
 
Name Description
Batch Used for batch processing of commands within HTTP protocol.
Case Used inside a Switch statement to perform a comparison.
Default Contains the default value of a field to which new item forms are initialized.
Expr Contains a CAML expression that is evaluated to determine the course of action for a Switch statement.
ForEach Provides a basic mechanism for enumerating a collection of views or fields defined in the current list.
GetVar Returns a variable in the context of rendering the page.
HTMLBase Returns a string that sets the base element for the current page.
HTTPHeader Used to set one of the HTTP headers.
HttpHost Renders the URL to the virtual server containing the current team Web site.
HttpPath Returns the path to the appropriate OWSSVR.DLL.
HttpVDir Returns the root directory of the current subweb.
IfEqual Allows for conditional rendering based on the comparison of two CAML expressions.
ListProperty Returns the value of a specified column in the List of Lists table.
Project The top-level element in ONET.XML that defines a template for a new Web site based on SharePoint Team Services.
ProjectProperty Returns a global property of the current team Web site.
Property Returns the property from the current ForEach context.
SetList Designates which list is current.
SetVar Sets variables in the context of rendering the page.
Switch Allows for conditional rendering based on the value of a CAML expression.
Today Renders today’s date.
View Defines a SharePoint Team Services view.
XML Used as an outer wrapper to denote a CAML data island on the page.
In Asp.net  and SharePoint, How to get all authenticated users?

    In sharepoint develop project or asp.net projects, Sometime we need get the all authenticated users by code. This post will talk about how to get all authenticated users?

Demo environment.

Windows 2003 server

sharepoint 2007

visual studio 2008

Scenario:

    In SPListItemEventHandler, config the item's permission automatically, the item has a [Is Public] property with Boolean type, if the property is checked, the all authenticated users can view the item.

The code as follow:

static string GetAuthenticatedUsers()

{

string str = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null).Translate(typeof(NTAccount)).Value;

WriteLog(str);

return str;

}

 

static void ProcessPermission(Guid siteID, string relativeWebUrl, Guid listID, int itemID)

{

SPSecurity.RunWithElevatedPrivileges(delegate()

{

using (SPSite site = new SPSite(siteID))

{

site.AllowUnsafeUpdates = true;

using (SPWeb web = site.OpenWeb())

{

web.AllowUnsafeUpdates = true;

SPList list = web.Lists[listID];

SPListItem item = list.GetItemById(itemID);

 

// clear userpermissions

if (!item.HasUniqueRoleAssignments)

{

item.BreakRoleInheritance(false);

}

 

for (int index = item.RoleAssignments.Count - 1; index >= 0; index--)

{

item.RoleAssignments.Remove(index);

}

 

// owner

string author = item[SPBuiltInFieldId.Author].ToString();

WriteLog(author);

SPUser owner = ((SPFieldUserValue)list.Fields[SPBuiltInFieldId.Author].GetFieldValue(author)).User;

WriteLog(author);

SPRoleAssignment ra = new SPRoleAssignment(owner.LoginName, owner.Email, owner.Name, owner.Notes);

ra.RoleDefinitionBindings.Add(web.RoleDefinitions.GetByType(SPRoleType.Contributor));

item.RoleAssignments.Add(ra);

 

if (string.Concat(item[FD_IsOpen]).ToLower() == bool.TrueString.ToLower())

{

// all authenticated users

ra = new SPRoleAssignment(GetAuthenticatedUsers(), null, null, null);

ra.RoleDefinitionBindings.Add(web.RoleDefinitions.GetByType(SPRoleType.Reader));

item.RoleAssignments.Add(ra);

}

else

{

// team members

SPFieldUserValueCollection team = item[FD_TeamMembers] as SPFieldUserValueCollection;

if (null != team)

{

foreach (SPFieldUserValue fuv in team)

{

WriteLog(fuv.User.LoginName);

ra = new SPRoleAssignment(fuv.User.LoginName, fuv.User.Email, fuv.User.Name, fuv.User.Notes);

ra.RoleDefinitionBindings.Add(web.RoleDefinitions.GetByType(SPRoleType.Reader));

item.RoleAssignments.Add(ra);

}

}

}

 

if (!site.AllowUnsafeUpdates) site.AllowUnsafeUpdates = true;

if (!web.AllowUnsafeUpdates) web.AllowUnsafeUpdates = true;

 

item.SystemUpdate(false);

}

}

});

}

 

public override void ItemAdded(SPItemEventProperties properties)

{

try

{

base.DisableEventFiring();

WriteEventInfo(properties);

ProcessPermission(properties.SiteId, properties.RelativeWebUrl, properties.ListId, properties.ListItemId);

}

catch(Exception ex)

{

WriteException(ex);

// write log

}

finally

{

base.EnableEventFiring();

}

}

1 - 5 Next