Contents tagged with Office Open XML

  • Custom code with SharePoint Online and Windows Azure

    Tags: .NET, C#, SharePoint, Visual Studio, Microsoft Office, Office Open XML, Windows Azure

    When I first heard about SharePoint Online at the PDC 2008 I was a bit disappointed that you could not use custom code but had to rely on the built-in functionality and the things you could do with SharePoint Designer (which is quite powerful anyway, especially with jQuery).

    To read more about SharePoint online, head over to Tobias Zimmergrens blog.

    But with some clever techniques you can take advantage of the Windows Azure Hosted Services and create your custom code. I will show you how to create some custom code, which normally is done by SharePoint event receivers or timer jobs, using a Worker Role in Windows Azure.

    The post is quite lengthy but I have skipped some of the code snippets to make it easier to read. You will find downloads of the C# code at the end of this post.

    Scenario

    This sample assumes that we have a Document Library in SharePoint Online containing Word 2007 documents for Proposals. The library is called Proposals. We want to make sure that our Proposals has all comments removed before we send it away to our clients. This comment removal procedure will be initiated by a workflow.

    The Document Library

    Action column The Proposals Document Library is a standard SharePoint Document Library with versioning enabled. First we add a new column to the library called Action. This column will contain the status of the comment removal procedure. It has the type Choice and three possible values; RemoveComments, Processing and Done.

    The workflow

    Using SharePoint Designer we create a new workflow, called Prepare Proposal. The workflow has three stages. The workflow is initiated manually

    1. SPD Workflow designerSet the Action column to the RemoveComments value
    2. Wait for Action column to get the value Done
    3. Send e-mail the the author

    Pretty simple workflow but all using the out-of-the-box SharePoint Designer activities.

    So far everything is basic SharePoint Online “development”, but now we head on over to the custom coding parts.

    Create the Hosted Service Worker Role

    Using Visual Studio 2008 and the Windows Azure SDK we can create a new project of the type Worker Cloud Service. This cloud service will contain all our code for removing the comments from our Word documents.

    Cloud Service templates

    When the project is created, actually a solution with two projects, we add two references to our Worker Role project; WindowsBase.dll and DocumentFormat.OpenXml.dll (from Open XML SDK 1.0). The Open XML reference must also have the Copy Local property set to true, so that the assembly is deployed with the hosted service App Package.

    Note: Version 2 of Open XML SDK can not be used since it does not have the AllowPartiallyTrustedCallers attribute, which is required for all referenced assemblies in Windows Azure.

    Add a service reference

    The worker role will use the SharePoint Online web services to read and update data so we need to add a Service Reference to our SharePoint online site and the Lists.asmx web service. When this is done an App.config file is created, just delete it - we have to set our bindings and endpoints in the code so it is fully trusted.

    In your worker role Start method you create code as follows:

      1: BasicHttpBinding binding = new BasicHttpBinding();
    
      2: binding.Security.Mode = BasicHttpSecurityMode.Transport;
    
      3: binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
    
      4: binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
    
      5: binding.Security.Transport.Realm = WorkerRole.Realm;
    
      6: binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;

    WorkerRole.Realm contains a string with your SharePoint Online Realm with a value something like this: “XXXXXmicrosoftonlinecom-1.sharepoint.microsoftonline.com”.

    Let’s code!

    The worker role will poll the Proposals library for new documents which has the RemoveComments value in the Action column. This is done with the GetListItems method and a query selecting only those documents.

      1: XElement query = new XElement("Query",
    
      2:     new XElement("Where",
    
      3:         new XElement("Eq",
    
      4:             new XElement("FieldRef",
    
      5:                 new XAttribute("Name", "Action")
    
      6:                 ),
    
      7:             new XElement("Value",
    
      8:                 new XAttribute("Type", "Choice"),
    
      9:                 "RemoveComments"))));
    
     10: 
    
     11: XElement queryOptions = new XElement("queryOptions");
    
     12: 
    
     13: var itemsXml = client.GetListItems("Proposals", string.Empty, query.GetXmlElement(), null, string.Empty, queryOptions.GetXmlElement(), string.Empty);
    
     14: 
    
     15: XNamespace s = "http://schemas.microsoft.com/sharepoint/soap/";
    
     16: XNamespace rs = "urn:schemas-microsoft-com:rowset";
    
     17: XNamespace z = "#RowsetSchema";
    
     18: 
    
     19: var docs = itemsXml.
    
     20:     GetXElement().
    
     21:     Descendants(z + "row").
    
     22:     Select(x => new {
    
     23:         Title = (string)x.Attribute("ows_LinkFilename"),
    
     24:         Id = (string)x.Attribute("ows_ID"),
    
     25:         Url = WorkerRole.Url + "/Proposals/" + (string)x.Attribute("ows_LinkFilename")
    
     26:     });
    
     27: 

    Now we have all our proposals in the docs variable and we can iterate over it.

      1: foreach (var doc in docs) {
    
      2:     RoleManager.WriteToLog("Information", "Processing: " + doc.Title);
    
      3:     setStatusOnDocument(client, doc.Id, "Processing");
    
      4: 
    
      5:     WebRequest request = HttpWebRequest.Create(doc.Url);
    
      6:     request.Credentials = new NetworkCredential(WorkerRole.Username, WorkerRole.Password);
    
      7: 
    
      8:     MemoryStream mems = new MemoryStream();
    
      9: 
    
     10:     using (WebResponse response = request.GetResponse()) {
    
     11:         using (Stream responseStream = response.GetResponseStream()) {
    
     12:             byte[] buffer = new byte[8192];
    
     13:             int offset = 0;
    
     14:             int count;
    
     15:             do {
    
     16:                 count = responseStream.Read(buffer, 0, 8192);
    
     17:                 offset += count;
    
     18:                 mems.Write(buffer, 0, count);
    
     19:             } while (count != 0);
    
     20:             using (WordprocessingDocument wpDoc = WordprocessingDocument.Open(mems, true)) {
    
     21:                 RemoveComments(wpDoc);
    
     22:             }
    
     23:             using (WebClient wc = new WebClient()) {
    
     24:                 wc.Credentials = new NetworkCredential(WorkerRole.Username, WorkerRole.Password);
    
     25:                 wc.UploadData(doc.Url, "PUT", mems.ToArray());
    
     26:             }
    
     27:         }
    
     28:     }
    
     29:     setStatusOnDocument(client, doc.Id, "Done");
    
     30:     RoleManager.WriteToLog("Information", "Comments removed from: " + doc.Title);
    
     31: }
    
     32: 

    First of all we have a method which updates the Action column of the item to Processing to indicate to the users that we are currently processing this document. Then we read the document into a stream and pass it into a WordprocessingDocument object. On that object we do the RemoveComments method which removes all comments in the Word 2007 document.

    Note: Have a look at Eric Whites blog for some nifty operations on your Open Xml documents, such as the remove comments function.

    When all comments are removed we upload the file back to SharePoint and set the status to Done, and we are all set.

    As you can see I use three different techniques to read from the SharePoint Online site; the SharePoint web services, request-response and a simple WebClient. Isn’t coding fun!

    Test

    One of Windows Azures beauties is that you can test it on your local machine using the Azure Development Fabric. Just hit F5 in Visual Studio.

    Development Fabric

    This allows you to debug and fine tune your code and see how it scales out.

    Deploy to Windows Azure Staging environment

    Hosted Service When you are sure that there are no bugs just choose Publish in Visual Studio and it will open up a web browser which directs you to the Azure Services Developer Portal, there you can create a new Hosted Service Project or choose an existing one to use for this Proposals service.

    To deploy this solution we have to upload two files; the  App Package containing all your code and references and the Configuration Settings file, both automatically created by Visual Studio.

    Deploying

    When this is done you have to wait a few minutes so Windows Azure can allocate resources for you and prepare the environment. Once this is done you are ready to test your service in the cloud.

    In staging

    Just hit the Run button and after a minute or so the Proposals Service is running - in the cloud!

    Deploy to Production

    For us used to the SharePoint environment and the mess it is to get from development to staging to production environment it’s so much fun to just hit Deploy in Windows Azure to move the Staging service to Production.

    Production

    As you can see from the image above this solution is now in production and started with one worker role.

    Run the workflow

    Now we can test our complete solution by uploading a document containing some comments. Then initiate the Prepare Proposals Workflow.

    Prepare Proposal

    The document will be updated with a new value in the Action column.

    In Progress

    After a few seconds the document is updated by the cloud worker role we created, the workflow completes, there are no more comments in the document and the author should have received an e-mail with information that the workflow is done.

     Done

    Summary

    This was a short demonstration on what you can do with the standard functionalities of Microsoft's cloud offerings such as SharePoint Online and Windows Azure. The scenario was quite simple but using the same techniques you can elevate your SharePoint Online experience and functionality a lot.

    Using Windows Azure is one possibility to host your online custom code, hosting it on on-premise servers is another option and it works just as fine.

    Note: I have not made this sample so it can scale out nor does it handle any exceptions. Take it what its for.

    If you would like to look at the code you can find it here.

    Happy coding!

  • How to make SharePoint index Office 2007 files

    Tags: SharePoint, Microsoft Office, Office Open XML

    If you install Windows SharePoint Services 3.0 on a new server you will find that your Office 2007 (.docx, .xlsx etc) files is not indexed as they should but the old binary document (.doc, .xls etc) format is indexed. This is due to the fact that the Office 2007 IFilters is not installed by your WSS installation.

    To resolve this issue you have to download the Microsoft Filter Pack and install it on your server. This will install the actual IFilters which are used for indexing the Office 2007 files.

    Then you have to tell the WSS Search Service to index those files, this is a manual registry operation. All details is found in the How to register Microsoft Filter Pack with Windows SharePoint Services 3.0 Knowledge Base article. To describe it short; first you have to tell the gatherer which file extensions to handle by adding all extensions to the registry. Then you have to connect all the extensions to the correct IFilter guid. After all this is done you have to restart the Search Service.

    Normally this works fine, but in some cases I recreated the whole index database to get things up and running fast.

  • PDC 2008: Day 4, wrapping it up

    Tags: Microsoft, SharePoint, Visual Studio, Microsoft Office, Office Open XML, PDC 08

    So the last day of PDC 2008 is over. The brain has been cooked for a few days…

    This very day did not have any keynote and I kicked off with a session on the Visual Studio Extensions for SharePoint. I have note used this add-in since the first releases of it since I didn’t like it that much but had instead relied on manual packaging and deployment as well as STSDev. But after this I might think about moving over and try it out once again. During the session a basic site was built with some lists, event handlers and a Silverlight application using the new Charting controls.

    Then I headed over to listen on the work on the Open Xml Formats SDK. Some nice demos of how you can merge, edit and create documents without using the Office clients. Some demos on how to integrate it to SharePoint was included. Version 1 is now available and based on the ECMA OOXML standard and version 2 will be available when Office 14 hits the street.

    Next I sat down and tried out some more of Azure and Quadrant. The Quadrant tool is amazingly interesting and at the same time confusing – I wonder what it eventually will end in…

    I ended the day with an introduction to F#. Really good session and Luca Bolognese explained it well by creating a real-world solution using F#. The syntax is really weird for me who is a natural-born-imperative-programmer, but I can see the usage for it and I hope that I can try it out in a project sometime. F# is currently available as a CTP but will RTM during 2009, and my guess that it will be installed with Visual Studio 2010.

    PDC 2008 was a great experience and it will return to LA next year. I have had the fortune to meet some really smart people from Microsoft and from other companies. I will return home with a head full of new stuff that I need to dig into deeper and a bag full of merchandise. Now I just can’t wait to start working with all of this exciting stuff.

    One thing I missed though was any “official” news on the Office 14 clients and SharePoint 14 platform.

    Having one more day here in LA I will try to get some hours out in the sunlight instead of sitting inside and being a geek.

    That’s all folks.

  • PDC 2008: Day 3, the picture is getting clearer

    Tags: .NET, SharePoint, Internet and the Web, Office Open XML, PDC 08, Windows 7

    Day three is officially over, I’m pretty tired today after staying up to late yesterday and playing around with the “goods”. I installed Windows 7 and tried it for a while, but to my disappointment I found out that the nice stuff that were shown on the keynote was missing in my release…

    This morning started with the last keynote of PDC 2008 and it was Microsoft Research that should be in the spotlight. An hour and a half was filled with stuff such as environment and healthcare studies done by MSR, important, but hey – you have an audience of 6.000 programmers/geeks here… The last 20-30 minutes was cool though, they showed up a kids-programming-language called Boku (not only for kids, for me too!) and Second Light an evolution of Surface, where you can project a secondary image onto a surface that is above, yup not in touch with, the surface. Really cool!

    First session I attended after the keynote was about how to architect services for the Live Framework – It’s all about using HttpWebRequest and RESTful services. If you know about these you can work with the Mesh and Azure. Now I’m just waiting for my activation codes for Azure and that Live Mesh will support non-English regional settings..

    I took a quick lunch so I could do one of the hands-on-labs with Microsoft Surface. Easy lab, but I spent some time extra and played with it. All is based on WPF and XAML and it’s really easy. Finishing the lab allowed me to claim the SDK for Surface, which otherwise is quite expensive, so I will have it within a few days. All that then remains is someone to hand me $12.500 so I can replace my living room table at home with a brand new Surface machine!

    Then it was time for some more of the Oslo stuff and this time the Quadrant application. Quadrant is the program to use when you are visualizing the repository you have described using the M-language. It’s one heck of a tool which you can turn inside out and more, but the question still remains – how will this really be useful? I’m sure that Don Box and his crew had a lot of fun making these tools and languages, but at this “pre-alpha” stage of Oslo, I have hard to tell how to apply this to my daily work.

    To ease things up I went to a talk about Oomph, an incubator project from Microsoft that tries to take advantage of the Microformats such as hCalendar and hCard. The session was a little to light-weight but shows the intention from Microsoft to take advantage of existing standards.

    Last session of the day was a long awaited talk from Miguel de Icaza on the Mono project, an open source version of .NET that runs on Linux, Max and Windows machines. Miguel made some really nice demos and it was neat to see how far Mono has come. I did participate in the first release of Mono with some contributions. Mono has some really nice features, such as the C#5(?) compiler as a service, and some sweet JIT optimizations that makes Mono worthy as a game framework. The Mono project also implements a Linux version of Silverlight, version 1.0 will ship any day now and version 2 will be at beta for Mix 2009.

    The Mono talk, Oomph talk, Windows 7 Wordpad with ODF/OpenXml support and a bunch of different framework released under the MS-PL open source license really makes me see a Microsoft in change.

    Before finishing the day off I walked around and talked to various experts in the Meet the Experts reception at the convention center. Tried to get some more information on Office “14”, but in vain…

    During this day the picture of Windows Azure is getting clearer, but the picture of Oslo is still quite blurry. I still have hard to find out to what Oslo is really about but I think I’m getting there – I have to try it some more.

  • PDC 2008: Day 2 with Windows 7 and Office Live

    Tags: Microsoft Office, Office Open XML, PDC 08, Windows 7

    Day two is official over. I’m just back from the attendee party at Universal Studios.

    Keynotes

    This Tuesday started with a couple of keynotes. I was fortunate and arrived just as they opened the keynote hall and got myself a seat in the front row.

    Me as a keynote frontrower

    After Ray Ozzies intro Steven Sinofsky took over and showed Windows 7 for the first time in public. You can read about the demos on almost every blog, but here are the stuff that caught my attention:

    • New and improved taskbar
      • better grouping/sorting of programs
      • applications are shown as icons, instead of text and icons, with spacing that adapts to the number of icons
      • you can pin applications to the taskbar, so they are shown there even if they are currently not running which makes the Quick Launch redundant
      • Jump Lists; for example shows the MRU list of Office applications
      • Improved Notification Area (formerly known and stilled referred to, in the keynote as System Tray) defaults to not showing the icons
      • the square to the right of the Notification Area is the Show Desktop function
    • Docking of windows
    • Wordpad supports both ODF and OpenXml
    • Booting directly off a VHD – isn’t that heaven for us developers!
    • Home networking that works…I’m not sure until I see try it
    • Ok, there is touch capabilities and they look neat, but it will take some time until I get my hands on hardware that is capable of this
    Windows 7 touch capabilities

    Visual Studio 2010 was also shown and it will be completely based on WPF and contains some really neat new features. How about having several web.configs! One for debug, one for staging and one for production! It’s there…

    Windows Live wave 3 is coming and is now a service on top of Windows Azure. The APIs looks slick and is based on standard REST protocols.

    Then it was Office time. I sure had hopes to see something from the Office “14” server products. Nope. Instead we were shown the Office “14” clients and Office “14” online sharing documents between the client, web and mobile devices. Office Online will really be something and Google Apps have to watch their back! The demo were they co-worked on a OneNote “14” document from the OneNote client, the OneNote online client and a cell phone was awesome – this is how I want to use OneNote!

    After a break Don Box and Chris Anderson hit the stage and made a really nice show (not rehearsed according to Don at a later session). They really showed how easy it was to work with Windows Azure using shipped bits and protocols, such as WCF and REST. Of course there were no PowerPoints but just Visual Studio and the command prompt.

    Keynote with Don Box and Chris Anderson

    Sessions

    After a lunch, with a nice guy from Microsoft Excellent Engineering, and after picked up the hard drive with the goods, I went to the session on Microsoft Velocity. Velocity is a distributed cache that really can easy your work with caching on large farms. The cache is easy to install and manage and really easy to program with. It has built-in support for redundancy and fail-over and scales unlimited. Velocity is currently at CTP2 and will be shipped during mid 2009 as a standalone product to ASP.NET.

    Next session was on the “M” language, a part of the Oslo project. I have not really understood the full capabilities with “M”, but to sum it up you can use M to model your domain languages. “M” is a language to describe types, values and constraints. It contains a compiler which can generate T-SQL from your “M”-code and then you can run the T-SQL and create a database with the types and constraints you specified and fill it with the specified values.

    Last session for this day was on how to architect services for Windows Azure. This was a pure PowerPoint session which described how to design and what to think of when you create applications/services for Windows Azure. All of this Windows Azure seems to be clearer for every day, can’t wait to get home and try it out some more. It feels almost to easy to build, configure and manage the services you build. You can just with a click scale out your application. If your application fails on one node, Windows Azure will try to restart the service or node and if that fails it allocates a new node for you. Why can’t I stop thinking about Skynet!

    Then back to the hotel and a quick change before I took a bus to the Universal Studios, where I met up with some nice Swedes and went for a few rides.

    That’s it for today. Now I have to continue my Windows 7 installation. Stay tuned for more “commercials”...

    Technorati tags: , , , ,

  • Office System 2007 Service Pack 2 announced

    Tags: SharePoint, Microsoft Office, XPS, Office Open XML, PDC 08

    I gladly received the news that the Office team announced Service Pack 2 for Microsoft Office 2007. Not only for the clients but also for the server products (read SharePoint).

    First of all it’s the support for the different file formats that I long for (ODF for example) and then there is the Outlook performance – both of these are addressed! XPS and PDF will be supported from scratch – no need to install a free plugin (just as it was in the Office 2007 betas).

    Unfortunately we will not se support for the ISO ratified OOXML format (IS29500) until Office “14” – wonder if we get some news at PDC 2008 about that?

    Technorati tags: , , , , , ,

  • Ecma is requesting comments on XPS

    Tags: XPS, Office Open XML

    Ecma International is currently asking ISO members for comments on the XPS standard. XPS is a new XML based standard for a paginated document format, somewhat like PDF.

    The current working draft 1.2 is now publicly available for anyone and the technical committee (TC46) of Ecma is requesting comments on the XPS draft. They also provide an issue list with all identified problems and an optional status.

    XPS has gained a lot of support from hardware/printer manufacturers, such as Konica Minolta and Xerox and software companies such NiXPS and SANATech.

    Ecma, and Microsoft, is taking this process a bit slower than the previous and controversial OOXML fast-track, which is good for everyone. Let’s see how the comments (or FUD) looks like this time…

    Technorati tags: , ,

  • Summertime

    Tags: Personal, SharePoint, Internet Explorer, Windows Vista, Windows Server 2003, Office Open XML

    It’s summer and time for some vacation, finally. This year has been hard work so far – and I don’t expect it to get lighter this upcoming autumn and winter. I’ve had fun though!

    Summer

    Microsoft SharePoint has really been one thing occupying my work – it feels like everyone is not just looking at SharePoint, they want to use it now! We have a couple of cases that is really interesting and I hope that I have convinced them and proposed a nice solution.

    About half a year ago, I predicted about 2008, half of them has come true; Windows Vista Service Pack 1, Internet Explorer 8 (only beta so far), nice parental leave (you bet) and OOXML ISO approval (not quite there yet, but anyway's).

    Some things are yet to come, I hope; XPS submittal to ISO, time over for msfeedicon (sorry about all you out there waiting for it – but I have some plans…), testing new Media Center (this one could come true any day, Fiji is in private beta) and upgrading customers to Windows Server 2008 and SQL Server 2008.

    I would like to add some new things to the list; Townsquare (this could really turn the heat up), PDC 2008 (I really hope I can go there) and Windows 7 beta (or as it might turn out to be Windows Vista R2).

    That’s all for me for now, don’t expect to much blogging over the next few weeks…

  • Aftermath of Swedish OOXML vote

    Tags: XPS, Office Open XML

    The Swedish Standards Institute has as a result of the chaotic OOXML vote in August changed their rules for participating in technical committees and voting in them.

    Previously you could just before the vote sign the agreement and participate. From now on you must have been a member of the technical committee at least three weeks ahead of the votes you would like to participate in. The new rules also clearly points out that you only have one vote (I'm still wondering who voted twice...).

    I think this is a good idea, but I have a feeling that in any similar cases (read XPS) in the future, the "stuffing" will begin three weeks ahead of the vote instead.

  • Official ISO FAQ on OOXML

    Tags: Office Open XML

    ISO has published an official FAQ on ISO/IEC 29500 aka Office Open XML. The FAQ contains official answers from ISO to common questions such as:

    Why two standards?

    The ICT industry has a long history of developing multiple standards providing similar functionalities. After a period of co-existence, it is basically the market that decides which survives...

    What about contradictions?

    ...but these can be taken care of during the maintenance of the standard.

    Via Doug Mahugh.

About Wictor...

Wictor Wilén is a Director and SharePoint Architect working at Connecta AB. Wictor has achieved the Microsoft Certified Architect (MCA) - SharePoint 2010, Microsoft Certified Solutions Master (MCSM) - SharePoint  and Microsoft Certified Master (MCM) - SharePoint 2010 certifications. He has also been awarded Microsoft Most Valuable Professional (MVP) for four consecutive years.

And a word from our sponsors...

SharePoint 2010 Web Parts in Action