Monday, April 07, 2014

How to use ProgId in SharePoint Custom Actions

This is somehow old topic but people(developers) keeps asking how to use the ProgId (PROGrammatic IDentifier) option in SharePoint Custom Action.

Some people that work with SharePoint don't have a clue this about this option and how to use it (MSDN documentation is not very good about this topic in SharePoint...).
There is a nice article talking about this subject in a declarative way, that can recommend a first view, link.
for more information about a tool that could manage this task please access the following link
SharePoint App Processlynx Custom Action and Ribbon Manager
or use the Free version Custom Action and Ribbon Manager in Office Store.

This article try to explain how we can create the Custom Action (not declarative or SSOM but JSOM) using the Parameter ProgId and how SharePoint handles this Parameter when this options is selected.

The first thing i can say is, the ProgId is about the structure of content we are working (XML) and not file type. 

The first thing we should know, the progid is about the XML structure of your document.
For this example we can create a normal Microsoft Word Document with some content, like is shown in the image bellow


After the content of the document is fill out, you should save the document as XML format as show in the image bellow.



For this example was created a Document with the Type "Word.Document" that is associated with Word. This is the type of document the XML structure is made, and this is the value the Custom Action will use to add the Action.


After this XML Structure validation you can upload the File to the Document Library and there you can see a little difference in the icon, Both selected documents has the type of associated (Word/Excel) but the file is XML, SharePoint assume the XML files (Examples2.xml and Book1.xml) with parameter "Word.Document" or "Excel.Sheet" that is coming from the XML and shown in the associated icon.

Create the Custom Action associated with ProgID 

After added the documents you can create your new Custom Action using “User Custom Action” SharePoint Object and define a custom action (Alert) to that will be associated with files from the Type “Word.Document”.
for more information about a tool that could manage this task please access the following link
SharePoint App Processlynx Custom Action and Ribbon Manager


For this example i used a Tool created by processlynx AG (Swiss Company) that will be available in the SharePoint app store to create Custom Actions and Ribbons using Wizards that any Site Administrator could use (simple and useful).



If you need the ECMAScript example for this custom action you can look in the following Code example:

var newUserCustomAction = UserCustomActions.add();
newUserCustomAction.set_name('My ProgIDAction');
newUserCustomAction.set_title('My ProgIDAction');
newUserCustomAction.set_description('My ProgIDAction');
newUserCustomAction.set_location('EditControlBlock');
newUserCustomAction.set_sequence(0);
newUserCustomAction.set_registrationId('Word.Document');
newUserCustomAction.set_registrationType(3);
newUserCustomAction.set_url('javascript:alert(\'Test\')');

newUserCustomAction.update();

After the Custom Action is created the option will appear to the Menu Item as "My ProgID Action" and fires the alert "Test".


If you try to access to the Document with the extension “.Docx” the custom action don’t appear.


Question: I already saw this options in the file "docicon.xml", it's is related?
NO, it is not related. The ProgId Custom action is directly associated with Listitem field Data (ProgId and HTML File Type Columns).
The docicon.xml is used to manage (Open, read, etc...)documents and association with file types.

How this ProgId is Manage in SharePoint Data and Custom Action

The Custom Action ProgId is validated by the ListItem Column "ProgId" and "HTML File Type" and verify if the Identifier is the Same. 
For our example the Custom action will appear if the item has the field "Word.Document"
You can access to ListItem Data and fields/columns using the “SharePoint Client Browser for SharePoint 2010 and 2013” tool.


Question: Can we use the Registration type “File Type” for this?

The answer to this question is no, like the name say's is about the extension of the file and not about the ProgId associated to the file and metadata and Structure of the type of File.
"<?mso-application progid="Word.Document"?>"

Add Custom Action for FileType

The following example show the parameters we can use for add the custom action to a file type (XML), this option will make the action associated with File type but not with the structure of the XML. 


After this change, the the custom Action will be associated to all xml Files


Conclusion

The Option PRogID can be great feature when you are working with OPEN XML, Office Document and XML structure and you need to define specific Action for this type of Files.


Links that could help you:
App to Manage Custom Actions and Ribbons
SharePoint App Processlynx Custom Action and Ribbon Manager
"Processing Documents in Bulk Using SharePoint 2010 and Open XML 2.0"

Hope you like the article, 
Kind regards,
André Lage
Post a Comment