Fun and games with SharePoint and Open XML

I’m starting to work on a SharePoint project right now that sounds like it should be simple, but is actually kind of complicated. Or at least if seems to me like it is, possibly because I’m still new to SharePoint and I’m not always stumbling across the “right” way to solve the various problems I’m encountering.

The basic problem is to take a purchase requisition, stored as a normal SharePoint list item, and allow the user to save it to a nicely-formatted Word document or PDF, so that it can be sent out to a vendor as a purchase order.

I went through quite a few ideas for this, most of which are likely very wrong. What I’ve settled on, for now, is creating a new ASP.NET application page which will take the ID of the purchase requisition on the query string. I can then link to this page through a custom action on the regular list item display/edit form. The new page will read the fields of the list item via the SharePoint object model, substitute them into a Word document template, then allow the end-user to download that document from their browser.

Previously, I’ve always used third-party libraries, such as EPPlus, to generate Word and Excel files. But, in this case, I wanted to avoid third-party DLLs and see if I could do what I needed with just the Open XML SDK.

I’m discovering a lot of interesting things about Open XML as I go. First, there’s a tool in the Open XML SDK, called the “Productivity Tool”, that can take a Word document and generate the C# code necessary to create that Word document from scratch. When I started working on this project, I was concerned about where I would store the document template; now, it turns out that I don’t have to store it at all! I can just generate it from scratch in code each time. And I can just modify the generated code a bit so that the values I need to substitute in can be variables instead of constants.

The generated code, unfortunately, is pretty messy. My first shot at running my purchase order template through the tool resulted in 10,000 lines of code. I made some changes in the document to simplify things, and I got down to about 7500 lines, which is still a lot.

I also discovered the “Power Tools for Open XML” library, which can be used to simplify the formatting on a Word document a bit. I ran it on my template, then generated new C# code, and now I’m down to 7200 lines. Still a lot, but it’s manageable.

So it seems like I now have a viable solution that doesn’t need to read or write anything to/from the file system, doesn’t have any oddball DLL dependencies, and should be pretty straightforward to code, test, and deploy.

SharePoint development

I’ve written a few posts recently about my initial attempts to get started with SharePoint development. I got a few notifications on Monday from WordPress, letting me know that I had new blog comments waiting for approval, all on those SharePoint posts. They were all extolling the virtues of a certain company that provides cloud VMs for development and testing, including SharePoint VMs. (And I’m pretty sure these comments were written by an employee of that company.) I considered approving and posting them, since they did seem to have been written by an actual human, and they were somewhat relevant. But it bothered me that this person felt they had to add comments to every post I wrote that mentions SharePoint; if it was just one comment on one post, I would probably have gone ahead and approved it. But commenting on multiple posts, with nearly identical comments and links back to that company’s site and blog, is kind of questionable. Not quite spam, but close.

I had actually considered signing up for an account with these guys and using one of their SharePoint VMs to get started, until my dev VM at work could be set up. But I decided to just wait, and now that I’ve got the VM at work, I really don’t need a cloud VM. I would still consider them if I ever needed to do some SharePoint work outside of my day job, and if I could justify the cost.

Regardless, my dev VM at work is now all set up, and I’m actually doing some real SharePoint development. I’m finding it to be an enjoyable change of pace from my usual Dynamics AX work. I only have 8 GB of RAM allocated to my VM, and I have a fairly complete SharePoint install on it, but things are still working reasonably quickly.

The debugging experience is better than I expected it to be. It’s really no different than debugging a regular ASP.NET page. I’ve heard so many bad things about SharePoint development, I was expecting it to be a real bear, but it honestly hasn’t been bad.

a trip to New York, and new glasses

I took a trip into NYC today, to visit the new Whitney, take a walk on The High Line, and see about buying a new pair of glasses at Warby Parker.

My eyes haven’t changed much over the last decade, so I just haven’t bothered getting new glasses for quite a while. The last ones I bought, about ten years ago, are still in good shape. But I think my vision has changed enough that it was time for new glasses. I knew that going back to the same optician where I got the last glasses would be convenient, and I’d likely get another great pair of glasses, but I also knew it would be very expensive, so I kept putting it off.

I was a little leery of Warby Parker, but I’ve been hearing good things about them, and a friend just got glasses from them, and they have a store right by the High Line and the new Whitney, so I decided to stop by and see what they could do for me. I have a very strong prescription, so their $99 glasses are actually going to cost me $225, but that’s still a lot better than the $700 or more that I’d have paid to get a new pair from the local optician I used for my last pair. The frames I picked out are clearly not quite as sturdy as my current ones, but hopefully they’re good enough. And on the web site, they’re listed as women’s frames, though they were specifically recommended to me by a store employee who could clearly see that I wasn’t a woman. But I guess they’re gender-neutral enough, and they looked ok on my face, from what I could tell. It’s likely that I’ll need to switch to progressive lenses or bifocals within the next few years anyway, so I may not need to keep these glasses as long as I’ve kept my current ones. They should be ready in a couple of weeks. Warby Parker has a 30-day return policy, so I guess if I don’t like them I can just return them.

After Warby Parker, I walked over to the new Whitney. I’d only been in the old Whitney once or twice, but I liked it. (That old building has been acquired by the Met, and should reopen as the Met Breuer next year.) The new Whitney is really great. After buying my ticket, I took the elevator to the top floor (the eighth) and worked my way down, using the outdoor staircases when I could. It’s a nice space, with a lot of room for them to show off a lot of work. Their current main exhibition, America is Hard to See, fills most of the museum, and has some nice paintings, including one from Jackson Pollock that I don’t think I’ve ever seen before, and a few from Georgia O’Keeffe. There’s much more of course, and I’d really like to go back and take another look. (And I probably will, when I go back to Warby Parker in a couple of weeks to pick up my glasses.)

After the Whitney, I took a stroll on the High Line. It was quite crowded, which I guess should be expected on a beautiful spring day. But it was a nice walk regardless.

Comic Book Heaven

I just watched this, and thought it was really great. This guy reminds me a bit of the guy who ran the comic book store in Elizabeth that I used to go to when I was a kid. He sold only back issues, no new books. And he fixed small electric appliances too, so the store was full of musty old comics and broken toasters. Those were the days!

Microsoft Build

I kept an eye on the news coming out of Microsoft Build yesterday. There’s a good overview at The Next Web. At some point, I’d like to try out Code on my Mac. It’ll be interesting to see if it gets any traction, and how this affects Xamarin Studio. There are a lot of short articles out there on Code, but there’s not much substantial information in any of them. I just checked Scott Hanselman’s site, though, and he has a good post up about it. He makes it clear that this is more of an editor than a full IDE:

This a code-focused and code-optimized lightweight tool, not a complete IDE.

So it’s not exactly a direct competitor to Xamarin Studio. Maybe more of a competitor to Sublime Text? This makes me wonder, though, if they have bigger plans for Mac/Linux, or if this is just a weird little side project that will fade into oblivion a few years from now.

new Evernote pricing and plans

Evernote announced new plans and pricing today. In a nutshell, there’s a new “plus” plan for $25/year, and the “premium” plan is now $50/year. The old premium plan was $45/year, so that’s a fairly minor increase. My premium subscription is up in early 2016. Rather than renew, I’ll probably switch to the “plus” plan, as it seems to be more than adequate for my needs.

I’ve known for a while that they were likely to make some pricing changes this year, but wasn’t sure what they were going to do. I was a little bit afraid that they might decide to make their premium plan $99/year or something like that. I’m glad to see that they haven’t bumped it up too much, and have actually added a cheaper plan that should be more than enough for many people.

setting up a SharePoint 2010 development VM

I’ve blogged previously about my failed attempt to set up a SharePoint dev VM at home, on my laptop. I’ve given up on that for now.

But one of the SharePoint projects at work finally got far enough through the “spec” phase that I could justify asking our IT ops people to help me get a SharePoint dev VM set up at work. The regular help desk guys set up the base image (Windows Server 2008 R2), and the SharePoint admin guys then installed SharePoint 2010 on it, so I don’t have too much insight into that part of the setup.

Having been handed a working VM with SharePoint 2010 Server installed, it was then up to me to get Visual Studio up and running. That wasn’t much of a challenge. I installed VS 2012 Ultimate. The installer actually gives you the option to install the SharePoint tools, so I didn’t even have to do that separately.

I did have a bit of a problem, post-install, in that some Windows Update that came down automatically killed SharePoint. I had to re-run the SharePoint config wizard several times, make a couple of registry patches, restart some app pools in IIS manually, and so on and so forth. In the end, I’m not entirely sure which combination of random trickery was actually responsible for getting things running again, but whatever it was, I seem to have a working environment again.

But that pretty much killed the entire day, so I have to say that setting up a working SharePoint dev VM is not a trivial task, even if you’ve got experienced admin guys doing the bulk of the initial setup work.

Monty Python

I went into New York today, and saw a couple of Monty Python films, as part of the Tribeca Film Festival. I saw Life of Brian (which I hadn’t seen in many years) and The Meaning of Live, which is a new documentary, mostly about the final Python live shows from last year.

Life of Brian had a Q&A afterward with John Cleese and Terry Jones, and Meaning of Live had a Q&A with Cleese, Eric Idle, and Michael Palin. So, now I’ve seen all of the (surviving) Pythons, except for Terry Gilliam.

It would have been fun to go to the Holy Grail screening last night too, but that one was pretty expensive. The Q&A for that one had all the Pythons, though, plus John Oliver, so that would have been awesome!

Seeing these films has made me think about the value of humor, and realize that I’m really not getting enough of it lately. On my way home, I picked up the Weird Al guest-edited issue of Mad Magazine, so that should help restore some balance. (It’s been many years since I picked up an issue of Mad.)

lots of WordPress updates

My site updated to WordPress 4.1.3 automatically this morning, only a few days after updating to 4.1.2. And now, WordPress 4.2 is out. I just went ahead and manually updated to 4.2, and applied a handful of theme and plugin updates.

It’s good to see that everyone is keeping WordPress up to date, patching security issues and adding features. Honestly, though, there have been a lot of updates in the last few weeks. Let’s all take a break for a few days, ok? 🙂