how to apply custom action in ECB only for document item - menu

I have added a menu item in edit control block(ECB) in document library(using following msdn article http://msdn.microsoft.com/en-us/library/ms473643.aspx)
Now i found that the custom action(menu Item) in ECB is displayed for both document item and document folder. So how to apply custom action only for document item?

Are you using list as your RegistrationType?
Try using ContentType as your RegistrationTypeand specify the guid of the Document Content Type (I think its 0x0101) in your RegistrationID.

You will need to create a class which inherits from WebControl. This class will need to render out your menu item as you want it displayed.
You then need to use the ControlAssembly and ControlClass parameters from your CustomAction definition to specify this class.
Your class will need to detect the if the current item is a document or folder and render/not render itself accordingly.
I would get the control working first just displaying a link, then add the logic in later.
This is a good blog posting on the technique, its not for the ECB but the principals are the same.
Enjoy!

In your customAction use RegistrationType="FileType" to determine FILE and use a RegistrationId="doc" to determine a extension, my exemple use word document. ;-)

Related

Access content field from views in Orchard CMS 1.10.1

I would like to display certain first level menuitem in bold.
This setting should be done by a checkbox when the user create / edit a menu item. (I have a workaround using the Model.Href, but it is not nice).
So I created a boolean field in Content definition / Menuitem URL (I don't know the name of the corresponding content definition in English Orchard).
How to access a custom field (Content Field) from a view?
(There already is a view which is used to customize the menu)
The examples I found use custom shapes, where the fields are accessed as built in fields (e.g. Model.ContentItem.FieldName ). But this is a different case.
With the help of "Piedone", the solution:
Model.Content.ContentItem.MenuItem.FieldTechnicalName.Value
Explanation
Examining the Model object in Visual Studio, the Model is a dynamic shape that have eg. Href property and a Content.
Content is a MenuPart, that is a content part that have a ContentItem property with the content item itself. Technically only content parts have Fields. When you (seemingly) add a field to a type it will be a part corresponding the type's name, that is MenuItem in this case (It's confusing that the display name of 'MenuItem' content type is Custom Link...)
The field's technical name is as you name it. When you add to a type, the Value will be a property of the BooleanField class. (By the way, it is nullable, so if you dont't save after adding the field, it will be null else the value you set).

Find ID or Class of Sharepoint Document Library

I have a Mega Menu navigation that generates its content from custom lists. Each 'Tab' on the Mega Menu links to a different document library. I want to highlight the tab of the currently selected document library.
Each 'tab' already has a class attribute but I am having trouble giving the document library an ID or Class attribute, or finding one that is already there.
I have added a content editor web part in one of the document libraries, which is a blank html text file that has a body ID. When I reference it in the CSS I am able to achieve the highlighting of the tab when on that document library. However this only applies to the certain view that I am in. When changed to another view on the same document library (I have about 15-20 views) the highlighting disappears because there is no content editor web part in that view.
So to sum up - how can I use a universal ID or Class attribute that will not change each time a view is changed in a document library?
Thanks.
I ended up just using jQuery for this. Put it in my master page in a script tag.
if ( document.location.href.indexOf('<string in URL - I used the name of the document library') > -1 ) {
$('UL#topnav A.SecondTab').css('background-image', 'url(highlightedtab.jpg)');
}
Used several if statements because each tab has a different class name, e.g. FirstTab, SecondTab etc.

How can I present a library as a custom view?

I have a Sharepoint library that is currently rendering as the usual folder and document items table list view.
I would like to use present the same information as a grid of folder and document icons with some nice jQuery hover animations to show tooltips on the item the icon represents.
I suppose what I am really trying to find out is how to add a new library view that allows me to specify the markup rendered per item. I could write a new webpart to query the list and use an ASP:Repeater but I don't want to have to specify a webpart property each page to tell the webpart where it should open the list from.
You can use List View Web Part with custom XSLT.

SharePoint:FormField in a custom webpart?

On my home page, I want a simple webpart that allow users to quickly fill an entry in a list.
The list have, let's say, three fields : title (text), body (rich text), category (lookup).
I don't want to use the standard DataFormWebPart because I have a bit of code-behind that also fill some technical hidden fields of my list (actually, I don't exclude the DataFormWebPart, but I didn't find how to use it with code behind).
So I started to implement a custom webpart. Because I don't want to have to handle manually each field input, I started to use the FormField control, which automatically choose the rendering control, and provide a Value property with the correct format :
<SharePoint:FormField runat="server" id="fldTitle" FieldName="Title" />
This code is not sufficient, I have to specified the listid :
<SharePoint:FormField runat="server" id="fldTitle" FieldName="Title" ListId="{title list guid}" />
This is working quite correctly. I can in code access the fldTitle.Value to retrieve the user input.
BUT I have to include the webpart in a properly packaged and deployed feature, that can be activated. The webpart will always target the same list, but as the list is also instanciated in the feature (ListInstance element), I can't know the Guid in advance.
I've tried using several technics to set the list ID on the fly, but without success.
I've also "reflectored" the SP dlls to notice FormComponent class are using a "Context" that is set by ListFormWebPart.
Finally, my questions are :
is it the correct way to create a custom input webpart on the home page (not a list custom form) ?
how can I keep the behavior of the FormField (choose the right control and handle the input and its conversion to the storage format) ?
Will I have to create a custom ListFormWebPart ?
May I play with ControlTemplates ?
thanks in advance for the help... I'm struggling with this simple case for days now...
I think that customizing form templates is the easiest way to customize list forms. Since custom form templates are implemented as user controls you can add whatever code you want.
See the following article:
http://www.codeproject.com/KB/sharepoint/SharePointListForms.aspx

Default content editor in list form doesn't allow image alignment

I need to be able to adjust the alignment of an image in an "Enhanced Rich Text Field" in an announcements list in MOSS 2007. However, the default content editor in the edit form for the list doesn't provide a way to do that. What's the fastest way for me to make sure users can align images? My first thought was to customize the DispForm.aspx and EditForm.aspx pages, but they just have the ListForm web part in the content region and as far as I know, you can't customize the ListForm web part from the designer.
You can't customize the LisForm web part, but you can add a "custom list form" to create a custom edit form. Maybe you haven't seen this article: http://weblogs.asp.net/jan/archive/2006/11/06/Custom-Edit-Forms-for-SharePoint-2007-Lists.aspx
Then you could do some javascript hackery to insert your own button which then calls something similar to existing RTE_InsertImage function to call a pop-up window and do whatever you need (you'll find this function in 12\template\layouts\1033\form.js)
I fail to see (or understand) your issue. I created a new announcements list, created a new item, inserted an image, aligned it to the right, viewed the item and it worked.
Then I proceeded to create a new custom column, choose multiple lines,enhanced rich text field, edited my list item, added an image, centered it, viewed and it was also working.
The only thing I noticed is that the "rich" control does not appears on non-IE browsers.

Resources