Domanda

Sto creando il mio pulsante di nastro personalizzato usando Questo articolo come riferimento.Il mio codice nel file Elements.xml va come questo:

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

C'è un modo migliore per modificare il codice JavaScript nell'attributo CommandAction, come ad esempio che avrebbe intelligense almeno per oggetti JavaScript di base come document?A partire da ora sto usando XML Editor che è piuttosto semplice.Altri editor come editor di codice sorgente e editor HTML non aiutano neanche.Anche la casella degli strumenti è vuota quando sto modificando Elements.xml e non riesco a capire che tutti i tag sono disponibili per me per Elements.xml.

Sto usando Visual Studio 2012.

È stato utile?

Soluzione

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.

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top