New sample project for SP2010 Word Automation: UI

11 comments

I’ve just published a second sample solution for the SP2010 Word Automation project on CodePlex. This solution will add a button to the Ribbon when browsing document libraries:

Ribbon button

When the button is clicked a modal Dialog is shown that will allow the user to specify the options used for conversion:

Modal Dialog

When the Ok button is clicked the selected files will be added to a conversion job and the job will be started.

The dialog is launched by some javascript that is specified in the CommandUIHandler section of the ribbon button definition.

<commandUIHandler
Command="SP2010WA_Convert_Button"
CommandAction="javascript:function convertDocument() {
Sys.loadScripts(['/_layouts/SP2010WordAutomation.UI/SP2010WordAutomation.UI.js'], function() {
SP2010WordAutomation.UI.ConvertDocument();
});
}
convertDocument();"
EnabledScript="javascript:function oneOrMoreEnable() {
var items = SP.ListOperation.Selection.getSelectedItems();
var ci = CountDictionary(items);
return (ci > 0);
}
oneOrMoreEnable();" />

I’ve decided to use the beta version of the ASP.Net 4.0 AJAX client library to load the required scriptfile when it is actually needed. While this is not completely necessary in this case, because the amount of script in there is quite little, it could provide a speedboost because the browser won’t load and interpret the script when the page loads.

The definition also contains some script to enable the button only when one or more files are selected.

The following lists the script that is loaded and called when the button is clicked:

Type.registerNamespace("SP2010WordAutomation.UI");

SP2010WordAutomation.UI.ConvertDocument = function () {
var items = SP.ListOperation.Selection.getSelectedItems();
var selectedItems = '';
var k;

for (k in items) {
selectedItems += '|' + items[k].id;
}

var options = {
url: '/_layouts/SP2010WordAutomation.UI/ConvertDocument.aspx?items=' + selectedItems + '&source=' + SP.ListOperation.Selection.getSelectedList(),
title: 'Convert Documents',
allowMaximize: false,
showClose: true,
width: 600,
height: 480,
dialogReturnValueCallback: SP2010WordAutomation.UI.ConvertCallback
};

SP.UI.ModalDialog.showModalDialog(options);
}

SP2010WordAutomation.UI.ConvertCallback = function(result, target) {
SP.UI.Notify.addNotification(target, false);

SP.UI.ModalDialog.RefreshPage(result);
}

First I use the Type.registerNamespace method that is provided by the standard SharePoint scriptlibrary to make sure I don’t override other methods with the same names.

In the ConvertDocument function we then launch a SharePoint dialog that will load an ApplicationPage which provides the user with the options they can choose. The ConvertCallback function which is called when the dialog passes a result will add a notification message to the main screen.

To see how this mechanism can be used, please refer to this post by Vesa Juvonen

Related posts:

  1. CodePlex project for Word Automation Services
  2. 2 new worflow activities added to SP2010 Word Automation
  3. SP2010 Installation – Error creating configuration database
  4. Fix ASP.Net form submit behavior with jQuery
  5. Ribbon buttons and the Client Object Model
Tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

11 Comments

  1. Robert Wade
    Posted July 9, 2010 at 8:31 pm | Permalink

    This is exactly what I have been looking for. But when I add it to my site as a solution and then attempt to activiate it. it does not activate. is there something I am missed other than the wsp to deploy it?

  2. Peter Gerritsen
    Posted July 9, 2010 at 10:00 pm | Permalink

    Deploying the solution and activating the feature should be enough. Does the feature not activate or does it look like it doesn’t have any result?

    After activating the feature on a site, each document library should have the extra button “Convert Document”

  3. Paul Stankiewicz
    Posted April 11, 2011 at 11:20 pm | Permalink

    Hi Peter,
    I would like to add a status message after the user clicks the ok button that says something like “Document is being processed” to give the user some feedback.

    I tried adding something like this in the ConvertDocument.aspx.cs – btnOk_Click code but it didn’t work. Any ideas?

    string myMsgString = “Processing File”;
    this.Page.Response.Clear();
    this.Page.Response.Write(string.Format(CultureInfo.InvariantCulture,myMsgString));

    Thanks
    Paul

  4. Dustin
    Posted June 27, 2011 at 11:10 pm | Permalink

    Is there a way we can convert Word doc to a one note document.

  5. jony
    Posted October 16, 2011 at 4:29 am | Permalink

    My library did not show in “OutPut Library” drop down list

  6. Demetris
    Posted November 8, 2011 at 3:59 pm | Permalink

    Hi Peter,

    Is there a way to copy some properties from the file to be converted to the new converted file.
    For example, if we convert “doc1.docx” to “doc1.pdf” and “doc1.docx” has values for the columns “Title”, “Description”, “Category”, is there a way the new file “doc1.pdf” to inherit those column values ?

    Thank you,

    Demetris

  7. Peter Gerritsen
    Posted November 8, 2011 at 9:04 pm | Permalink

    Hi Demetris,

    In the codeplex version this is not included as a feature. I’ve created an implementation of this for a customer, but I’m not allowed to share this code unfortunately.
    The way it worked was that it created an item in a root list with information about the conversion. On this list a timer job was running that checked if a conversion had finished and would copy the metadata when that was the case.

    Regards,
    Peter

  8. Dave
    Posted November 17, 2011 at 5:37 pm | Permalink

    Hi Peter,

    Sounds like a great solution but I cannot seem to get it to work. I’ve added this solution, deployed it and activated the feature in the site features but the designer actions are not appearing in SharePoint Designer, am I missing a step in the configuration of the solution?

    Cheers,

    Dave

  9. Dave
    Posted November 17, 2011 at 5:52 pm | Permalink

    Ignore above, its working now.

    Cheers,

    Dave

  10. Micah
    Posted December 8, 2011 at 8:08 pm | Permalink

    I can’t get it to work on an environment hosting SharePoint on multiple servers (i.e. diff server for web front end (2), app pools, and database).

    What happens is when I click on the “Convert Document” icon in the ribbon the correct dialog opens but the dropdown for Output Library does not have the custom libraries for that site and when I click OK nothing happens and the dialog stays open.

    Any help?

  11. Peter Gerritsen
    Posted December 9, 2011 at 9:42 am | Permalink

    Hi Micah,

    The only advise I can give you is to do some debugging. As I’m not involved in SharePoint development anymore, I don’t have the tools to do this myself.

    Regards,

    Peter

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>