I have copied C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES\EventsList\Events\schema.xml into a custom list template feature. I have another feature that creates the list instance:
<ListInstance
FeatureId="58c1f9c9-eadb-41dd-a358-e04b2f2e30c0"
TemplateType="100322"
Title="$Resources:core,calendarList"
Url="$Resources:core,lists_Folder;/$Resources:core,calendar_Folder"
OnQuickLaunch="TRUE">
</ListInstance>
and then places a ListViewWebPart on the page:
<View List="$Resources:core,lists_Folder;/$Resources:core,calendar_Folder" BaseViewID="0" WebPartZoneID="TopRightRow" WebPartOrder="3" />
I activate the features and go to the site. The webpart says: There are currently no upcoming events. To add a new event, click "Add new event". I click Add new event, enter the information, and click Save. The page refreshes, the no upcoming events message disappears, but there are no items displayed! If I go to the calendar the list item is there. What gives?
I change the list instance definition so that it uses the out of the box template:
<ListInstance
FeatureId="00bfea71-ec85-4903-972d-ebe475780106"
TemplateType="106
Title="$Resources:core,calendarList"
Url="$Resources:core,lists_Folder;/$Resources:core,calendar_Folder"
OnQuickLaunch="TRUE">
</ListInstance>
When I rebuild the site, activate the features, and repeat the "add new" steps, the item is now displaying properly in the webpart after the page refresh.
I've backed out all of my changes from the custom list template. It is now identical to the OOTB schema. Why doesn't my custom list template work, but the OOTB list template does?
I have know idea why the OOTB template works, but I was able to fix my custom template.
First, remove the XslLink line from the BaseViewID="0" View in schema.xml:
<XslLink>main.xsl</XslLink>
Scroll down to the Toolbar/IfHasRights section. Change Case 4 from:
<Case Value="4"><HTML><![CDATA[<div class="tb"><img src="/_layouts/images/caladd.gif" alt="" /> <a class="ms-addnew" id="idHomePageNewEvent" href="]]></HTML>
<URL Cmd="New" /><HTML><![CDATA[" onclick="javascript:NewItem(']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<URL Cmd="New" />
</ScriptQuote><HTML><![CDATA[', true);javascript:return false;" target="_self">]]></HTML><HTML>$Resources:core,AddNewEvent;</HTML><HTML><![CDATA[</a></div>]]></HTML>
</Case>
to:
<Case Value="4"><HTML><![CDATA[<div class="tb"><img src="/_layouts/images/caladd.gif" alt="" /> <a class="ms-addnew" id="idHomePageNewEvent" href="]]></HTML>
<URL Cmd="New" /><HTML><![CDATA[" onclick="javascript:NewItem2(event, ']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<URL Cmd="New" />
</ScriptQuote><HTML><![CDATA[');javascript:return false;" target="_self">]]></HTML><HTML>$Resources:core,AddNewEvent;</HTML><HTML><![CDATA[</a></div>]]></HTML>
</Case>
This enables the new SharePoint 2010 popup NewForm.aspx behavior.
Next, change the provisioning of the webpart to:
<View List="$Resources:core,lists_Folder;/$Resources:core,calendar_Folder" BaseViewID="0" WebPartZoneID="TopRightRow" WebPartOrder="3">
<![CDATA[
<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
<Assembly>Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
<TypeName>Microsoft.SharePoint.WebPartPages.ListViewWebPart</TypeName>
<Title>Calendar</Title>
</WebPart>
]]>
</View>
This along with the removal of the XslLink line forces the webpart to render as a ListViewWebPart instead of as an XsltListViewWebPart.
Now the rendering between the two weparts is different, so as a last step, use the following style so that the add new link of the ListViewWebPart looks like the add new link of the XsltListViewWebPart:
div.tb {
border-top:1px solid #EBEBEB;
margin:3px 0 16px;
padding:9px 7px 3px 10px;
}
Related
I added a custom action to SharePoint list. In CommandUIHandler in EnableScript attribute I added a javascript function. Then I realised that it is being invoked twice. To be more specific:
1) When I enter a default view for the list and click "Items" in a Ribbon it is invoked once
2) When I select checkbox near the list item it is invoked twice?
I have some queries loading in a background so I don't want it to be called twice. Does anyone know whether it's a bug or SharePoint default behaviour?
<CustomAction
Id="Ribbon.Documents.TestGroup.AssignCard"
Location="CommandUI.Ribbon"
RegistrationId="10001"
RegistrationType="List"
ShowInLists="TRUE"
Sequence="26">
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition Location="Ribbon.ListItem.Actions.Controls._children">
<Button
Id="Ribbon.Documents.TestGroup.AssignCard"
LabelText="Assign"
ToolTipTitle="Assign a free card"
ToolTipDescription="Opens a form to assign a free card to a guest."
Alt="Assign"
Sequence="31"
Command="AssignButtonCommand"
Image32by32="/_layouts/1033/images/formatmap32x32.png"
Image32by32Top="-160"
Image32by32Left="-288"
TemplateAlias="o1" />
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler
Command="AssignButtonCommand"
CommandAction="javascript: document.ReceptionRibbon.AssignButton({SiteUrl}, {SelectedItemId});"
EnabledScript="javascript: console.log('1'); document.ReceptionRibbon.EnableAssignButton();" />
</CommandUIHandlers>
</CommandUIExtension>
I managed to solve the issue by setting a temporary boolean variable to false when query starts, and setting it back to true when it ends.
How can I target custom ribbon action menus for specific list views? I want to be displayed in the default view of the list but to be hidden in the other views.
Any ideas?
Though the question is old, yet unanswered , I am responding to it.
Create an empty Sharepoint Project in VS2010 , add an Elements.xml file in the project and past following XML in it.
<CustomAction Id="MyCustomButton" Sequence="999"
GroupId="Manage"
Location="CommandUI.Ribbon" // Location to display button
RegistrationId="101" // on every list, for a specific list or library put the GUID of list here e.g. RegistrationId="{GUID_OF_LIST}"
RegistrationType="List"
Rights="ManageWebs"
Title="Custom Document Library Button">
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition Location="Ribbon.Documents.Manage.Controls._children">
<Button Id="Ribbon.Documents.Manage.Controls.CustomButton" TemplateAlias="o1"
ToolTipDescription="Creates a server side action."
ToolTipTitle="SSRibbon" LabelText="SS Action"
Image32by32="/_layouts/images/ContractClaims/newproject.jpg"
Image16by16="/_layouts/images/ContractClaims/newproject.jpg" Alt="New Project"
Command="{3E04C0C1-12DD-449E-905F-7E88EB9E22B1}"
Sequence="20"/>
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler Command="{3E04C0C1-12DD-449E-905F-7E88EB9E22B1}"
CommandAction="javascript:alert ('Hello World' ) ;" />
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
The several locations to display the button can be found here.For more on the top you can google respective XML elements.
You can use EnabledScript parameter in CommandUIHandler, where you can put javascript code and check if specific page/list/view is loaded.
link to similar answer
Example:
<CommandUIHandler
Command="Ribbon.ListItem.CustomGroup.Controls.BtnSayHello.Command"
CommandAction="javascript:alert('Hello');"
EnabledScript="javascript:
function isEnable(){
if(location.href.indexOf('AllItems.aspx') > 0){
return true;
}
return false;
}
isEnable();"
/>
I have a requirement to display SharePoint fields as a footer on only certain pages, so this rules out a master page change, and I haven't had any success with plain-old HTML.
What I'm trying to display is the following code:
<SharePoint:DeveloperDashboard runat="server"/>
<div class="s4-notdlg" style="clear:both; background-color:orange; padding:10px">
<SharePoint:CreatedModifiedInfo ControlMode="Display" runat="server">
<CustomTemplate>
<br>Page Contact: <SharePoint:FormField FieldName="Page Contact" runat="server" ControlMode="Display" DisableInputFieldLabel="True" />
<br>Last modified on <SharePoint:FieldValue FieldName="Modified" runat="server" ControlMode="Display" DisableInputFieldLabel="True" />
by <SharePoint:FormField FieldName="Author" runat="server" ControlMode="Display" DisableInputFieldLabel="True" />
<br>Comments: <SharePoint:FormField FieldName="Check In Comment" runat="server" ControlMode="Display" DisableInputFieldLabel="True" />
</CustomTemplate>
</SharePoint:CreatedModifiedInfo>
</div>
When editing the page in Advanced Mode, no matter where I place the code, I break site definition. Is there a good place to insert this code in the page? Or does the Site Definition need to be changed.
Breaking the Site Definition may not be what you are thinking. It is just saying to you that the page is not one of the 'defaults' anymore, as a way to identify what have been customized on the site.
Every edit you make on those pages are like that, so it is OK to get that message. You may also "reset to site definition" when you want to, but this is not usually very stable on my experience.
I am having four external list "List1", "List2", "List3", "List4". I have added a custom ribbon button Like:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="ATEAgWorkOrderButton"
RegistrationType="List"
RegistrationId="600"
Location="CommandUI.Ribbon">
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition
Location="Ribbon.ListItem.Actions.Controls._children">
<Button
Id="Ribbon.ListItem.Actions.ATEAgWorkOrderButton"
Alt="Click on this button to Add"
Sequence="3"
Image32by32="/_layouts/Images/Project/image.png"
Command="ATEAg_WorkOrder"
LabelText="Add Detail"
TemplateAlias="o2"/>
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler
Command="ATEAg_WorkOrder"
CommandAction="javascript:alert("Hello Success");" />
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
</Elements>
The button is now visible in all the external lists. But I want to make it visible for only "List1" and "List2". How to do this?
You need to explore the Andrew Connell's Ribbon Customization Deep Dive.
http://www.andrewconnell.com/blog/archive/2011/04/16/sharepoint-2010-ribbon-customization-deep-dive.aspx
He goes into how to solve these problems. In short instead of binding a customization for all lists of a certain type, you can register a javascript function that gets called to determine if you button should be shown or hidden. In this function you can determine which list is currently active.
If all your lists are associated with a ContentType, you can set the registration id of the custom action to the ContentType id.
From MSDN:
RegistrationID: Optional Text. Specifies the identifier of the list or
item content type that this action is associated with, or the file
type or programmatic identifier (ProgID).
I have developed a list definition project and created a custom view aspx page to be the default view of the list. I would now like to add a custom webpart to be displayed in the custom view aspx page. Any ideas of how it can be done?
You can use a feature receiver and manage the addition of web parts during feature activation. Here is a bit of a stub to help get you started.
In the feature activated method call code similar to the following:
// Add web parts to the .aspx page that was provisioned
SPFile page = site.GetFile(<<page url>>);
Hashtable hashWebPartsOnPage = new Hashtable();
using (SPLimitedWebPartManager mgr = page.GetLimitedWebPartManager(PersonalizationScope.Shared))
{
try
{
// First, let's clear the existing web parts off of the form
foreach (System.Web.UI.WebControls.WebParts.WebPart webPart in mgr.WebParts)
{
hashWebPartsOnPage.Add(webPart.ID, webPart);
}
foreach (string webPartName in hashWebPartsOnPage.Keys)
{
System.Web.UI.WebControls.WebParts.WebPart webPart = hashWebPartsOnPage[webPartName] as System.Web.UI.WebControls.WebParts.WebPart;
mgr.DeleteWebPart(webPart);
}
// Add Part to the proper Zone
MyWebPart myWebPart = new MyWebPart();
//set web part properties
mgr.AddWebPart(myWebPart, "FullPage", 1);
}
finally
{
mgr.Web.Dispose();
}
}
page.Update();
On SharePoint 2010 you can add a custom webpart or SharePoint WebPart in the same view definition inside the Schema.xml of the List definition (I'm not talking about List instance).
Although isn't directly explained by MSDN, and if you look at the View Schema you can't see a '<WebParts>' definition, you can actually do something like this:
<View BaseViewID="7" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:CILSS_defaultView" DefaultView="TRUE" MobileView="FALSE" MobileDefaultView="FALSE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/generic.png" Url="CI_Projects.aspx">
<Toolbar Type="Standard" />
<XslLink Default="TRUE">main_cilss.xsl</XslLink>
<RowLimit Paged="TRUE">30</RowLimit>
<ViewFields>
<FieldRef Name="Attachments"></FieldRef>
<FieldRef Name="LinkTitle"></FieldRef>
<FieldRef Name="CILSS_ProjectDescription"></FieldRef>
</ViewFields>
<Query>
<OrderBy>
<FieldRef Name="LinkTitle" Ascending="TRUE"></FieldRef>
</OrderBy>
</Query>
<ParameterBindings>
<ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
<ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />
</ParameterBindings>
<WebParts>
<AllUsersWebPart WebPartZoneID="Main" WebPartOrder="2">
<![CDATA[<WebPart xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/WebPart/v2">
<Title>Default Home Webpart</Title>
<FrameType>None</FrameType>
<Description>Use for formatted text, tables, and images.</Description>
<IsIncluded>true</IsIncluded>
<ZoneID>Left</ZoneID>
<PartOrder>0</PartOrder>
<FrameState>Normal</FrameState>
<Height />
<Width />
<AllowRemove>true</AllowRemove>
<AllowZoneChange>true</AllowZoneChange>
<AllowMinimize>true</AllowMinimize>
<AllowConnect>true</AllowConnect>
<AllowEdit>true</AllowEdit>
<AllowHide>true</AllowHide>
<IsVisible>true</IsVisible>
<DetailLink />
<HelpLink />
<HelpMode>Modeless</HelpMode>
<Dir>Default</Dir>
<PartImageSmall />
<MissingAssembly>Cannot import this Web Part.</MissingAssembly>
<PartImageLarge>/_layouts/images/mscontl.gif</PartImageLarge>
<IsIncludedFilter />
<Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
<TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>
<ContentLink xmlns="" />
<Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor">
<Value><div>Create and view Project documents:</div>
<br/></Value></Content>
<PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
</WebPart>]]>
</AllUsersWebPart>
</WebParts>
</View>
This view definition includes a Content Editor Webpart in the list view called 'CI_Projects.aspx'
Remember to assign the WebPartZoneId and assign a BaseViewID different from the default views included in the List definition.
The webpart will provisioned on every List you will create with this List Definition. (obviously only on the named view.aspx you define).
Well i would like to access the list definition view page which i don't think will be accessible using the above site.GetFile() method. Any other options you think we can use to achieve it. I have tried the following steps:
Copy the OOB “ViewPage.aspx” and place it in the same folder as “CustomViewPage.aspx”
Create the custom web part which shows the items of the view with your custom approach.
Create a feature to provision the “CustomViewpage.aspx” along with your custom web part.
Create a custom list definition. In the schema.xml file of the definition for all the views mention the “SetupPath” to refer your “CustomViewPage.aspx”. With this step all the views mentioned in the list definition will use the “CustomViewPage.aspx” to create the view pages and as well all the views which you create after the creation of the list will use the “customViewPage.aspx” as the base page to create the view pages.
Step 1:
Just copy the OOB “ViewPage.aspx” and place it in the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\Pages folder as “CustomViewPage.aspx”
Step 2:
Create the custom web part which shows the items of the view with your custom approach. Basically use the GetViewfromUrl(“Lists//”) method to get the view and then retrieve the items in the web part. The code snippet for the custom web part looks like follows :
SPList list = SPContext.Current.List;
String strViewName =
SPView view = SPContext.Current.Web.GetViewFromUrl("Lists/list/ "+strViewName);
SPListItemCollection listItems = list.GetItems(view);
.
.
.
.
After getting the list items then do your custom approach of displaying the items.
Build the web part DLL and place it in the GAC.
Step 3:
Create a feature to provision the “CustomViewPage.aspx” along with your custom web part. By activating this feature the “Customviewpage.aspx” will be embedded with your custom web part. The elements manifest file content looks like follows :
<File Url="Pages/CustomViewPage.aspx" Type="Ghostable">
<AllUsersWebPart WebPartZoneID="Main" WebPartOrder="1">
<![CDATA[
<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
<Assembly>CustomWebpartforView, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e3483ddc8b0d437a</Assembly>
<TypeName> CustomWebpartforView.MyCustomview</TypeName>
<FrameType>None</FrameType>
<IsVisible>true</IsVisible>
<Title>Custom Web part for View</Title>
</WebPart>
]]>
</AllUsersWebPart>
</File>
This step gives me error for the source file path which i modified by giving the Path attribute in the File Tag
Step 4:
Now the base custom view page is available along with the web part. Now how to integrate the custom view page with the list definition. Create a custom List definition and for all the views defined in the schema mention the “SetupPath” to use the “CustomViewPage.aspx”. Now the custom view page will be used as the base view page for all the views defined in the list definition and as well the views created later also will be using the “CustomViewpage.aspx” as the base page. The sample snippet for declaring the views inside the schema.xml is as follows :
Install and activate the feature of your custom list definition.
Now with all these steps, when you create a list based on this custom list definition then all the views created will be using the “CustomViewPage.aspx” to create the view pages and your custom web part will be rendered instead of the OOB dataformwebpart. The views which you will be creating after the creation of the List (Through UI, Through Object Model) will also use the “CustomViewpage.aspx” as the base page to create view pages.
For some reason i am still unable to see the CustomViewPage.aspx with my custom webpart. Am i missing somthing or there is something missing in this article.