Archive for April, 2007

Zimmergren VSTO Tip #1: Extend the Ribbon-menu in Word 2007

April 18th, 2007 by Tobias Zimmergren

In this Visual Studio Tools for Office I will walk you through how to make a very simple customization to the Word 2007 (or any of these: Visio, PowerPoint, InfoPath, Outlook or Excel) Ribbon-menu and add our own button with some code to execute when it’s pressed.

Basically, what you need to do before doing anything else is to install and configure the VSTO add-in for Visual Studio. Just search www.microsoft.com/downloads for it and you will find it.

Once the prerequisites are installed, we will create a new project and choose the Word-template as seen in this screenshot:
vstoribbonword1

What we do next before doing anything else, is the following: Right-click your project in the Solution Explorer, choose "Add" -> "New Item…" and choose the Ribbon component, as seen in the following Screenshot:
vstoribbonword2

Once that’s done. Uncomment the commented code in the new Ribbon1.cs (or whatever you chose to call it).

Basically, everything’s done now. All we need to do is add some buttons or any other controls we would like to add in order to extend the Ribbon-menu.
In the following screenshot I’ve done only minor modifications to the labels and text and I havn’t added any other controls, to keep it simple:
vstoribbonword3

Note: I’m defining a method to be executed when the button is toggeled with this xml: onAction="OnToggleButton1"

The following code shows a simple method that’s implemented by default with some minor modifications to insert my signature when the button is toggeled (Best practice would be to use the button control, not the toggleButton.. I just chose to do it this way because I couldn’t care less to change the default ;)
vstoribbonword4

We’re done for now.
Execute the project and you’ll see the following screen with the option to press a toggleButton that will insert my very basic signature into the document:
vstoribbonword5

What I wanted to show with this blogpost was simply the fact that it’s quite easy to extend the Ribbon to enable the use of your own custom code. The possibilites are almost endless since you get access to the entire .NET Framework via the code and can do basically whatever you want.
You can also integrate the menu with SharePoint via the Microsoft.SharePoint namespace, however if you’re going to communicate with the SharePoint API I would suggest making a WebService with the required methods and host it on the SharePoint-machine and then call the WebService from your clients.

Note: In order for this to work on the client machines, I think you need to install the VSTO on them aswell (Note, a full installation of the Office-suite will enable this feature if I’m not mistaken). The clients will also need the .NET Framework installed.

That’s it for now. I hope someone could enjoy this simple VSTO Tip :)

Cheers people!

In this little tip I will show you how you can customize the "Site Actions" menu by creating a Feature to manipulate the menu and deploy it to your SharePoint site.

This post, as the previous in the series is just an overview of what can be done and will not be discussed in detail how things are done since it’s just a little tip. If you’d like to full post on how to create features or extend the menus, please leave me a comment.

The first thing I usually do is to launch an empty VS 2005 project and add a file called "Feature.xml" and a file called "Elements.xml"  to the project, and set the files’ Schemas-property to "C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATEXMLwss.xsd" in order to get the Visual Studio 2005 IntelliSense to work properly.

In this screenshot you’ll see my simple Feature.xml file:
zimmergrentipfour
Note: the GUID is simply generated by going to Tools -> Create GUID, then implement it without the { and }. The file is also referencing a file called Elements.xml that I created, see next screenshot.

This is the Elements.xml file:
zimmergrentipfour (2)

Now that those two simple files are created, all I need to do is create a new folder in "C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATEFEATURES" to host my feature, then deploy to my server.
See screenshot:
zimmergrentipfour (3)

Now we will deploy the feature by using the cmd-line tool STSADM.EXE, as you can see in the following screenshot:
zimmergrentipfour (4)
Note: Don’t forget to reset IIS in order for your feature to become availible

This is the result:
zimmergrentipfour (5)

In this little tip I’m creating a Sample InfoPath form to be published to my Forms Library on my site and then opened within the browser when you want to edit/update the form.

This is a sampleform from InfoPath:
publishinfopathforms

Bring up the Design Checker (Tools – Design Checker), make sure you don’t have any errors. Then click the "Change Compatability Settings…" link to get the following dialog:
publishinfopathforms (2)
Make sure the "Design a form template that can be opened in a browser or InfoPath"-checkbox is checked, and enter the URL of your server with InfoPath Forms Services in the URL-field.

Next, you will Publish the form.
Choose "File" -> "Publish" and follow these steps:
publishinfopathforms (3)

Make sure you enter the site where you want to publish the form (you will create a Form Library in following steps)
publishinfopathforms (4)

Just make sure the checkbox "Enable this form to be filled out by using a browser" is checked, and choose "Document Library" and click next.
publishinfopathforms (5)

Choose to "Create a new document library" in order to create a new library to host the forms
publishinfopathforms (6)

Enter a name, and click next again..
publishinfopathforms (7)

Add the columns that should be availible in the SharePoint sites and Outlook folders (as the text says in the dialog):
publishinfopathforms (8)

Just make sure the information in the next dialog is correct, then choose Publish to get your form published to your new Forms library!
publishinfopathforms (9)

Now the last thing you need to do is to go to the Form Library you just created, choose Settings -> Form Library Settings -> Advanced Settings and make sure you change the Browser-enabled Documents-setting to "Display as a Web page" in order to bring up the InfoPath form in your browser for editing (Not everyone have InfoPath installed on their machines)

publishinfopathforms (10)

 

That’s all you need to do! You now have a form that can be edited in the browser.
Next step is usually to connect a workflow to this library, so when a new form is filled out it will be sent to someone for approval or what not. Piece of cake with the built-in workflows. (Or developing one yourself in VS 2005/SPD)

I hope this enlightened someone.

Cheers, and happy eastern!

Zimmergren MOSS 2007 Tip #2: Retrieve stuff by code

April 5th, 2007 by Tobias Zimmergren

This is by no means meant to be anything other than a small tip on how to interact with the object model. If you need more information on how to interact and code with the object model, drop me a comment. But for now this is just to show you guys out there who havn’t done any coding with SharePoint, that it’s actually a piece of cake!

Start off by creating a new Visual Studio 2005 Windows Forms application.

Add the following namespaces: (Administration-namespace might not be needed depending what you want to do further from this point)

Also make sure you’ve got something in the Recyclebin that will show up when we launch our application later:

I made an interface like this, really hot:

Then just add the following simple code:

That’s all there’s too it! It’s not hard at all to interact with the object model. As you can see I’ve used the commonly used SPSite which contains the SPRecycleBinItem. From this point, you should know how to move on with this. An example, all you need to do in order to enable deletion of things in that recyclebin from your application is to use the .Delete() method of the SPRecycleBinItem called rItem in this case.

All very basic, should get you interested if nothing else!