2011-10-25 remarks
RegisterSod (key, url) the first letter of the key cannot be in upper case. Otherwise, the operation fails. The reason is unknown.
Sharepoint 2010 (sp1) does not use webapps to create documents when the office client is installed. After debugging the script, it is affected by the script, when the browser detects the OpenDocment ActiveX add-on, it will call createNewInClient to call the client Office; otherwise, it will use createNewInBrowser to call webapps.
var event = new Object(); event.fromRibbon=true; event.currentCtx = eval('ctx' + currentCtxId);
CoreInvoke ('createNewDocumentWithRedirect2',event,'http:\u002f\u002fzhfd-portaldev\u002fDocs\u002fDocuments\u002fForms \u002ftemplate.dotx', 'http:\u002f\u002fzhfd-portaldev\u002fDocs\u002fDocuments', 'SharePoint.OpenDocuments', false, 'http://zhfd-portaldev/Docs/_layouts/CreateNewDocument.aspx?id=http://zhfd-
portaldev/Docs/Documents/Forms/template.dotx', true, 1);
To use Webapps to create a document, replace the default createNewDocumentWithRedirect () and use the page script to find that core. js uses
<Script type = "text/javascript"> RegisterSod ("sp. core. js", "\ u002f_layouts \ u002fsp. core. debug. js? Rev = Qp5K7ycU \ u00252FEY9IvE0KOi7zQ \ u00253D \ u00253D "); </script>
To register to the page, we need to register the Custom Script behind core. js.
Solution:
1. Add a script file rj. js
Write the modified createNewDocumentWithRedirect ():
function createNewDocumentWithRedirect(strTemplate, strSaveLocation, strProgID, bXMLForm, strRedirectUrl, sron, defaultItemOpen) { ULSrLq: ; if (sron) { createNewInBrowser(strRedirectUrl, strSaveLocation, strProgID, defaultItemOpen); }}
2. Add an EmptyElement and write the registration script in CustomAction:
<CustomAction Id = "Ribbon. library. actions. newButton. script "Location =" ScriptLink "ScriptBlock =" function _ callback JS () {// register the Custom Script RegisterSod ('rj. js', '/_ layouts/TGPortal/rj. js'); // serves as the core. js affiliated RegisterSodDep ('SP. ui. dialog. js', 'core. js '); // load the script LoadSodByKey ('rj. js', '');} function _ uploload1 () {// in Core. after js loading is complete, execute _ response js () ExecuteOrDelayUntilScriptLoaded (_ response js, 'core. js ');} // set the script to BodyOnload and execute _ spBodyOnLoadFunctionNames. push ('_ upload1'); "/>
3. Deploy the solution. Use Chrome's Developer Tools to test whether createNewDocumentWithRedirect is a custom script.