So, technical stuff it is J As you'll start noticing when developing SharePoint apps is that you'll often want to create a GUID. Say for a feature or solution ID, or for your workflow. As I hope you'll be aware Visual Studio provides in this using External Tools found on the Tools menu, when configured correctly Visual Studio will display the Create GUID menu item:
Which starts the age-old GUID manufacturing tool, a tool that has been dealing out random bits of information for us since before I was probably born.
My grievance is that I actually need to start this tool to get a GUID, copy and then paste it, quite annoying. I decided to fix that little error.
I first tried to do a macro to copy a new GUID to the clipboard, but macro's don't run STA, so OLE calls to the clipboard failed.
Now comes the rocket-science of my thinking…
First you create a Console Application, which you creatively call 'GuidToClipboard'. Add in a reference to Windows Forms, and adorn the main method with the STAThread attribute. Write a whole single line of code and you're done here:
class
Program
{
[STAThread]
static
void Main(string[] args)
{
System.Windows.Forms.Clipboard.SetText(
Guid.NewGuid().ToString("B"));
}
}
This is probably the point in time where someone will say 'I can do that in PowerShell', and I'd say, 'Great, send me the script pls!'
To use this little wonder you first register the app as an External Tool, using the ToolsàExternal Tools menu in Visual Studio:
Next you go to ToolsàCustomize to add the custom tool as a command in a toolbar. To do this, first take note of the index of your custom tools in the dialog, for me it is the sixth item. On the Toolbars tab, I created a new toolbar called SharePoint, for 'me favorite SharePoint tools. Next you can drag commands into the toolbar using the Commands tab. On the Commands tab you need to select the Tools category on the left, and then you can drag the external tools from the right-hand pane onto your toolbar. You'll end up with a toolbar like the following. Note that instead of displaying the correct command name for the custom tools, it displays 'External Command X', where X is the index of the command. Kinda sucky, but it'll do.
When you close the dialog, it turns into:
Now you can click 'Get Guid' to get a GUID on the clipboard, just CTRL+V to paste in where you have your cursor.
Almost there!
To make stuff even easier than clicking on a button and pasting, you then go to ToolsàOptions. In the dialog, open the EnvironmentàKeyboard section, and configure the 'ExternalCommandX' with a short-cut key. Mine is index 6, and I use CTRL+SHIFT+G to get a GUID.
Now you can get a GUID in any document by pressing CTRL+G, and then CTRL+V. Cool!
Hope it helps!