0

I am creating my own custom ribbon button using this article as reference. My code in the file Elements.xml goes something like this:

<CommandUIHandler
    Command="NewRibbonButtonCommand" 
    CommandAction="javascript: MULTIPLE
                               LINES
                               OF
                               JAVASCRIPT
                               CODE">

Is there a better way to edit the JavaScript code in CommandAction attribute, such as it would have IntelliSense at least for basic JavaScript objects like document? As of now I am using XML Editor which is pretty basic. Other editors like Source Code Editor and HTML Editor don't help either. Even the Toolbox is empty when I am editing Elements.xml and I am unable to figure out which all tags are available to me for Elements.xml.

I am using Visual Studio 2012.

1

Yeah, it is pretty common problem. No matter how you try to edit your code it will be difficult to read, debug, manage, and update, when it is written inside elements.xml.

I know that question is about the editor itself, but sometimes it is much better to write your JavaScript code in another .js file, and use only reference in CommandAction. You can load your script in several ways from custom action xml:

  1. Write another custom action with ScriptLink location. Pros - easy to use, cons - it will be loaded on everypage inside your custom action scope (site, web, etc.). Show me how it is done.
  2. Use Script On Demand (SOD) technique to load your script dynamically from inside CommandAction script. SOD can give you magic, because it can load your script only when ribbon tab is opened and this way you can gain performance. Show me SOD 'bible'

Why this way is better. When you have your JavaScript code not in elements.xml but in external files and you need to update your code inside JavaScript it is much easier. You will not need to update your custom actions, you just only need to upgrade your JavaScript files, no matter there they are, in Style Library or in _layouts folder. Debugging of separate JavaScript file is also easier, that inline code.

0

While we are working with Sharepoint xml files like Feature.xml, Elements.xml or ONET.xml files we wont get any intellisense by default.

But for any developer it is hard to remember all these information. So, here is the easiest way to get the intellisense

  1. Open your xml file in Visual studio.
  2. Go to properties pane of the xml file and click on schema and browse for the file
  3. locate file named "wss.xsd" from C:/Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/XML/wss.xsd (12 for MOSS, 14 for SP 2010 and 15 for SP2013)

Note : this file will have all the xml defined functions which is easily recognized by the visual studio.

enter image description here

Then you will get the intellisense for the SharePoint solution..

Credit :- http://kancharla-sharepoint.blogspot.com/2012/03/how-to-get-intellisece-for-featurexml.html

  • Thanks for replying. But my Elements.xml file is already associated to Schemas. And I am looking towards IntelliSense to edit my JavaScript code in CommandAction attribute and for Toolbox I wanted something more visual like Design tab which seems to be missing in a lot of places in Visual Studio 2012. – Naveen Dec 23 '13 at 7:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.