Patrick’s Bytes

Techie for the past 30 years…

SharePoint On Vista! Another good reason for dev to use Vista?

Yup, you read it right, SharePoint can runs on Windows Vista thanks to Bamboo Solution’s setup helper here. Many thanks to Jonas for commenting it on my blog post.

Go check it out today, there is a walkthrough with screenshots as well. It shows Windows SharePoint Services but I guess it might work for MOSS 2007 as well. :)

What’s up? Going to Penang next week.

I am out of KL for this week and will be running some workshops and talks at Penang.

This coming Monday and Tuesday I will conduct a Getting Start with .NET programming workshop at MCSB Training Center at Island Plaza. With the help of my pal Ervin Loh, he updated the content of the workshop to use latest features from .NET Framework 3.5 and hands on labs are using Visual Studio 2008. My colleague Rahimah will also be running similar workshop at Cyberjaya at the same place.

image

After that on next Thursday I will do a What’s new with Visual Studio 2008 talk at Penang Skills Development Center, expect something cool to be demo.

image

Windows 7 demoed

Watch Bill Gates and Steve Ballmer talked about Windows 7. If you don’t know what is Windows 7, just FYI, XP is Windows 5.1 and Vista is Windows 6 then you will get the picture.

image image

I believe Windows 7 is years away because this demo is still using Windows Vista look and feel with multi touch technology inside. Interesting part of this demo would be:

1. The multi touch demo is done using existing Tablet PC in the market, which I don’t see additional hardware mounted on it.

2. Multi touch is done on some WPF applications, especially the familiar piano, this could mean that WPF with all their bells and whistles will also get multi touch enabled which make it more fun and cool !!

3. Multi touch capability demos and clients are still important and they will continue to evolved. There wouldn’t just a SaaS world with client OS being just cheap commodity.

Check out the videos here.

http://d6.allthingsd.com/20080527/gates-ballmer-video-part-1/

http://d6.allthingsd.com/20080527/video-bill-gates-and-steve-ballmer-highlight-reel-part-two/

http://www.engadget.com/2008/05/27/microsoft-shows-off-snippet-of-windows-7-at-d6-reveals-multi/

Replace content of <w:t> element inside Content Controls with data bound value from Custom XML part

In my previous post I discovered that Content Controls in WordprocessingML files which has data binding to a CustomXML part will not render properly. However, this ONLY apply if you programmatically replaces the CustomXML part but never modify the value of <w:t> within the <w:sdt> element just like in this Eric White’s video on YouTube or as per mentioned in the book [Pro SharePoint Solution Development] in Chapter 7 .

To make things clearer, lets look at the screen shots below. For a Word 2007 document with CustomXML data bound(AND also with the CustomXML modified programmatically), below is what it looks like by default when you open it with Office 2003 (or XP and 2000), the data does not appear (below).

image

Even though you see there is no problem when open it up with Office 2007 (below)

image

This is because the Compatibility Pack for Office 2007 File Format does not render the value data bound inside the <w:databinding> element but instead its take the value in <w:t> element, shown below:

<w:sdt>
- <w:sdtPr>
<w:dataBinding w:xpath=”/root[1]/name[1]” w:storeItemID=”{b6aa39be-c6d5-40ca-a66e-93dbd069104f}” />
  <w:id w:val=”3411243″ />
- <w:placeholder>
  <w:docPart w:val=”DefaultPlaceholder_22675703″ />
  </w:placeholder>
  <w:showingPlcHdr />
  <w:text />
  </w:sdtPr>
- <w:sdtContent>
- <w:p w:rsidR=”006D15FD” w:rsidRDefault=”00F43988″>
- <w:r w:rsidRPr=”00583873″>
- <w:rPr>
  <w:rStyle w:val=”PlaceholderText” />
  </w:rPr>
<w:t>Click here to enter text.</w:t>
  </w:r>
  </w:p>
  </w:sdtContent>
  </w:sdt>

So I created a generic project using the latest OpenXML SDK (April 08 CTP) and together with LINQ to XML to modify the content within <w:t> element with the value from the CustomXML part. You can download my full source code here, but basically this is how my solution works:

XNamespace w = @”http://schemas.openxmlformats.org/wordprocessingml/2006/main”;

        public void Convert(string fileName)
        {
            using (var wordDoc = WordprocessingDocument.Open(fileName, true))
            {
                var mainPart = wordDoc.MainDocumentPart;

                XmlReader reader;

                reader = XmlReader.Create(mainPart.GetStream(FileMode.Open, FileAccess.Read));

                XDocument mainXml = XDocument.Load(reader);

                string xpath;
                XElement t;
                var bindings = mainXml.Descendants(w + “dataBinding”);

This is where the magic works, grab XPath attribute value from all the <w:databinding> elements and then replace it into <w:t> element using GetValueFromCustomXmlParts method (details do refer my source code)

                foreach (XElement binding in bindings)
                {
                    xpath = binding.Attribute(w + “xpath”).Value.ToString();

                    t = binding.Parent.Parent.Descendants(w + “t”).First();
                    string textValue = GetValueFromCustomXmlParts(mainPart.CustomXmlParts, xpath, myns);

                    t.ReplaceNodes(textValue);

                }

                XmlDocument temp = new XmlDocument();
                temp.Load(mainXml.CreateReader());
                temp.Save(wordDoc.MainDocumentPart.GetStream(FileMode.Create, FileAccess.Write));
            }
        }

After that the Word 2007 document can be opened in Office 2003 and data are rendered successfully. This solution also works in other none-MS Office productivity suites such as ThinkOffice and WordPerfect.

image

Disclamer: This is just a quick fix or rather a proof of concept on how to solve the <w:databinding> element problem on a simple Word 2007 document, there are  many situations (or more complex document layout) I haven’t tested the solution on. Do download my solution at your own risk. If you bump into problems do let me know, but my help will only be on best effort basis.

By the way, here is Eric’s video on the new OpenXML SDK

[YouTube=http://www.youtube.com/watch?v=t_FYHd234ng]
YouTube – Open XML SDK demo and road map

image

MSDN Magazine revisits OBA development

It has been sometime since there is an issue of MSDN mag that focuses on Office Business Application development. I believe not since before Visual Studio 2008 released. Visual Studio 2008 does comes with a lot of new tools inside VSTO for OBA development and it is worth while to have a look what you can achieve easily here.

Editor’s note on why one should think of Office as a development platform http://msdn.microsoft.com/en-us/magazine/cc507637.aspx

Document Automation using VBA to VSTO
http://msdn.microsoft.com/en-us/magazine/cc507643.aspx

Automate Web App Deployment with the SharePoint API
http://msdn.microsoft.com/en-us/magazine/cc507633.aspx

Integrate VSTO with SharePoint Content Types
http://msdn.microsoft.com/en-us/magazine/cc507632.aspx

Older Posts »