Uncategorized

Microsoft hacks away at TechNet membership benefits (again)

1
share
 

TechNet Professional (formerly TechNet Plus) subscriptions are one of the best ideas to come from Redmond – allow IT Pros to pay a subscription, and evaluate pretty much all Microsoft software without time limits and expirations. Why is this such a good idea? Because Microsoft gets a significant portion of its revenue from business licensing, and making evaluation as easy as possible can only encourage adoption of new versions.

Last year, Microsoft silently dropped the number of licenses per application from 10 down to 5, arguing that for evaluation, there was no need for so many licenses. Perhaps, perhaps not. I create new VMs to evaluate software fairly regularly, and having 10 keys makes it much less likely to encounter activation issues.

But ok, we only get 5 – so we adjust.

Well, for some reason Microsoft has decided that they want to scale things back further – as seen on the subscription home page,


Beginning on January 26, 2012, individual subscribers to TechNet Professional Subscriptions may access a maximum allocation of 3 product keys for Microsoft Office and Windows Client products in connection with their subscription. The allotted keys may only be used for software evaluation purposes. Once the maximum keys have been activated no more keys will be made available. Additional product keys may be acquired through the purchase of an additional subscription.

Unfortunately, I just saw this today, so I’m doing like any reasonable person would and requesting all 5 keys for any Office or Windows related products before they drop it down again – until I hit the daily key request limit…

First of all, making software evaluation more difficult is only going to hurt Microsoft. But then again, Windows 8 doesn’t appear to be geared toward business AT ALL, so maybe it is indicative of a shift in strategy.
(It is odd that Windows 8 preview still isn’t on TechNet, nor is the System Center 2012 RC…)

If only TechNet members had the time to protest…

DIRECTV2PC activation key usage limit error

0
share
 

I have been trying to install DIRECTV2PC for a week or so (off and on of course) and I get the error “Activation Failed” with a reason of “activation key usage limit reached”

For some reason, nobody had a solution – on satelliteguys.us or dbstalk.com (or directv forums, or the internet as a whole).
I had already requested two keys, and I had only used them once – it seems ridiculous to me that I cannot use the key again if I, say, reinstall Windows (which I tend to a couple times a year)…

I found a workaround – use a different email address to request a new key. (Many email providers allow you to insert arbitrary periods in your email address…)

DIRECTV2PC is made by cyberlink for Directv. Nobody seems to know why it requires a product key – probably some accounting thing. Rumor has it that it may be going away soon anyway.

Good luck!

Definitive complete list of Office Ribbon Callback Signatures for 2007 and 2010

1
share
 

Microsoft’s documentation for programming the Office Ribbon is pretty sparse at best. There are two pages you can get Callback signatures:
1. Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)
2. Introduction to the Office 2010 Backstage View for Developers

Notice that neither of these documents sound like where you would expect callback signatures “part 3 of 3″, and “introduction to the…” Also, the backstage introduction article contains rehashes of most of the office 2007 callbacks in a painfully verbose fashion.

I am here to help.
How about an excel spreadsheet containing the callbacks, associated control, source (2007 vs 2010) and the signatures in 4 different languages? Did I mention the data is already in a table and sorted by callback name?

Here you go:
Full Office Ribbon Callback List
Update: I have uploaded this file to a public SkyDrive so it can be viewed online, since I have needed to make some changes:
Office Ribbon Callbacks

This document is not a control -> callback mapping. The typical use case is:
I am building Office customizations using xml.
I need to implement X callback, but do not know the signature.
I look up the callback by name, then make sure it is the correct one for my control.

Also, I didn’t quite finish reconciling some discrepencies between the 2010 and 2007 documentation – for example, in 2007 the getImage is supposed to return an IPictureDisp – which is a real pain in the butt. My experience showed that returning a bitmap worked anyway, and now the 2010 documentation says getImage returns System.Drawing.Bitmap. I have switched to using Bitmap because it is so much cleaner, but I figured I should leave them both in there.

I am open to suggestions – just trying to fill what I consider a documentation gap.

Pre Populate SharePoint Document Properties in a Word Document

0
share
 

The integration between SharePoint and Microsoft office contiunes to improve with every successive release, but as of Office 2010 and SharePoint 2010, there is still a bit of feature gap when it comes to automation.

When a document originates from within SharePoint it is not too bad – you have to do a little CustomXMLPart trickery to set the properties. But what if your file is a SharePoint virgin?

The adding a document to sharepoint adds at least 3 additional Custom Xml Parts to the Word Document – one of them big, complex and guid-filled. To generate these parts would be a bit of a nightmare.

Turns out, you don’t need all of the xml to pre-populate fields. Nor do you need any guids. Here is all the XML you need:

<?xml version="1.0"?>
<p:properties xmlns:p="http://schemas.microsoft.com/office/2006/metadata/properties" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pc="http://schemas.microsoft.com/office/infopath/2007/PartnerControls">
  <documentManagement>
    <SharePoint_x0020_ColumnName>Text Value</SharePoint_x0020_ColumnName>
  </documentManagement>
</p:properties>

I will leave it to you to figure out the column names (hint – spaces become “_x0020_”).

Store that xml bit in a string (say, xmlString), and call Document.CustomXMLParts.Add(xmlString);
Now, when the document is saved to sharepoint, the fields will be pre-populated, all the appropriate xsd and guids updated, and the user gets no errors about missing required fields!

Behaviour of Application.MailMergeAfterRecordMerge Event

0
share
 

The signature for the Application.MailMergeAfterRecordMerge event looks like this:

        void Application_MailMergeAfterRecordMerge(Word.Document Doc)
        {
        }

While I would have expected the Document referenced in the Doc parameter to be the newly created merged document, it is actually a reference to the document from which the merge occurred. In other words, it’s not really all that useful.

PreviewResults

Automate Word Mailmerge Preview Results

0
share
 

(Long story short: the property you need is ViewMailMergeFieldCodes. Set it to 0 to enable preview; -1 to disable preview)

The mail merge process in Microsoft Word is a bit of a bear to automate sometimes. I suppose I should be thankful that it can be automated at all, but there are bits of it that are very poorly documented, requring a bit of trial and error to work with. It doesn’t help that most Office interop documentation leans toward Visual Basic…

Anyway, today’s issue was attempting to programmatically Preview the results of a Mail Merge in a C# VSTO project, like the button in the ribbon:

Big surprise: Document.MailMerge doesn’t contain any properties or methods with the word “preview”

Turns out there is a property called ViewMailMergeFieldCodes that does what we need, but in reverse. Microsoft’s documentation states:

This property returns True if merge field names are displayed in a mail merge main document, and False if information from the current data record is displayed

Trouble is, the field is an int, not a bool! A little debugging to the rescue:
When this field is set to -1, Preview is disabled, and the field codes are displayed.
When set to 0, Preview is enabled, and the record data is displayed.

To switch the displayed record, change Document.MailMerge.DataSource.ActiveRecord.

Now if only there was an event that fired when the record changed…

On using a light bulb as a current limiter (and crude current meter)

0
share
 

If you search on Google for “light bulb current limiter” you should come across several articles, newsgroup and forum posts about the details of building one. (i.e. )

Essentially, you connect a incandescent light bulb in series with an outlet, so you can safely test a device that might be prone to blow a breaker, or draw so much current as to release magic smoke.

One common feature of many of these articles is the idea that the light bulb will “blow” if the device draws too much current. This is totally and completely false.

When a 60-watt light bulb is connected directly to mains, it will draw approximately 60-watts of power, or 500 milliamps at 120-volts. That is the maximum amount of power that it will permit to flow, and it will burn at full brightness.

When you connect a device in series with the light bulb, it is effectively acting as a resistor to the current through the light bulb. With a 60-watt bulb, a device that used 250-milliamps wired in series would cause the bulb to burn at about 50% brightness (although light bulb brightness as a function of current is non-linear so this is not entired true, this is just an example…)
Now let’s imagine a worst case scenario – what could be wrong with an electrical appliance that would cause it to draw the maximum amount of current? Why shorting the power cord of course.

If you short the power cord of a device attached in series with a light bulb, the circuit is 100% IDENTICAL to plugging the light bulb directly into the wall. Nothing blows up, nothing catches fire – the bulb limits the circuit to 60-watts.

So if you are testing an electrical device using a lightbulb current limiter, please be aware: the bulb will not stop the power if too much is used. It is up to you to know how much power your device should be using, selecting a light bulb of the correct wattage to prevent it from going above (or much above) this, and turning off the power if the bulb is burning at full brightness when it should not be.

rand_keys_mem

.NET multiple dictionaries with the same keys memory usage

0
share
 

I need to create some objects that will allow me to access columnar data by header name. The access looks something like this:

class ParentObj {
string[] columnNames;
ChildObj[] Children;
}

class ChildObj {
Dictionary<string, string> Items;
}

All the child dictionaries will have the same set of keys, matching the column list from the parent.

Now this particular object is going to be used on computers that are resource constrained, and could contain large quantities of data. My big concern was should I actually use separate dictionaries, or should I just store the values in an array, and lookup the column number from a single dictionary.

After trying both methods with very large random data, I found the memory usage to only increase 10megs using separate Dictionaries. Certainly not worth the added complexity of managing my own Dictionary implementation.

My next question was if the CLR was wasting a bunch of memory on a bunch of duplicate keys. CLR Profiler to the rescue!

I modifed my test program to be able to either use the same keys in all child objects, or use random keys as well. After making all the strings the same size, it was clear that .NET does not keep a separate copy of each of the duplicate strings around:

Object memory when all keys are the same:

Object Memory when the keys are random:

So in conclusion, using many dictionary instances with the same set of keys does not result in a significant amount of duplicate data in memory (or memory waste).

Getting the base Document from ThisDocument

0
share
 

When developing a document level Add-In in visual studio, you may have a need to pass the current document to another function. This is tricky, because ThisDocument cannot be cast to a document object.

Turns out, ThisDocument inherits DocumentBase, and has a property called InnerObject. This is the Document.

SortedSet wrapper for .net 3.5

4
share
 

Here is a VERY basic SortedSet wrapper for .NET 3.5
The SortedSet is one of the few new features of the .NET Framework 4.0 that I hate to go without. I recently had to drop a Class Library from 4.0 to 3.5, and the SortedSet was the only thing missing. So, I just created my own SortedSet that is build on the SortedList where TValue is a byte,

Here is my implementation – if you need any of the really fancy features, you will need to implement them yourself.

    public class SortedSet<T> : SortedList<T,byte>
    {
        public SortedSet() : base()
        {
        }

        public T Min
        {
            get
            {
                if ((base.Count) >= 1)
                {
                    return base.Keys[0];
                }
                else
                {
                    return default(T);
                }
            }
        }

        public T Max
        {
            get
            {
                if ((base.Count) >= 1)
                {
                    return base.Keys[base.Keys.Count - 1];
                }
                else
                {
                    return default(T);
                }
            }
        }

        public bool Contains(T value)
        {
            return base.ContainsKey(value);
        }

        public void Add(T value)
        {
            base.Add(value, 0);
        }
    }
Go to Top