Monday, November 10, 2014

Open JSON responses in IE

Internet explorer doesn’t like opening JSON response by default and will normally ask you to save the file. if you apply the following registry changes, then the JSON response will open in IE nicely. Although i think Firefox handles this better with nice formatting over CHROME or IE.

 

anyhow, here’s the reg fix.(you may want to back up these keys first if you want to revert)

Windows Registry Editor Version 5.00
;
; Tell IE to open JSON documents in the browser. 
; 25336920-03F9-11cf-8FD0-00AA00686F13 is the CLSID for the "Browse in place" .

[HKEY_CLASSES_ROOT\MIME\Database\Content Type\application/json]
"CLSID"="{25336920-03F9-11cf-8FD0-00AA00686F13}"
"Encoding"=hex:08,00,00,00

[HKEY_CLASSES_ROOT\MIME\Database\Content Type\application/x-json]
"CLSID"="{25336920-03F9-11cf-8FD0-00AA00686F13}"
"Encoding"=hex:08,00,00,00

[HKEY_CLASSES_ROOT\MIME\Database\Content Type\text/json]
"CLSID"="{25336920-03F9-11cf-8FD0-00AA00686F13}"
"Encoding"=hex:08,00,00,00

Friday, November 7, 2014

Surface Pro 3 – No Sleep Option

Just bought a new Surface Pro 3 and have been having some weird behaviour. Seems to start after i had finished installing Visual Studio 2013.

Was bugging me that the sp3 didn’t power up quickly or resume nicely. Turns out it was effectively powering off all the time as sleep mode was not available. Was also having some weird behaviour where touching the keyboard the keys would light up but the screen would stay blank for ages until I pressed a few more keys. Plus closing the cover would effectively hibernate my machine.

Further investigation highlighted that when I install windows phone emulators it enabled hyper-v which runs on the metal with win 8.1 above it. This disabled sleep mode as an available option!! (would be a problem on any win 8.1 machine, not just surfaces)

So best way around this is to use an admin command to disable hyper-v (http://winsupersite.com/mobile-devices/surface-pro-3-tip-hyper-v-vs-connected-standby)

Better still, is to create a new boot entry with hyper-v disabled and then select which you need at boot up. (http://www.hanselman.com/blog/SwitchEasilyBetweenVirtualBoxAndHyperVWithABCDEditBootEntryInWindows81.aspx)

I’ve actually done the opposite of what Scott Hanselman said as I want my default win 8.1 boot to be hypervisor disabled and for my ‘other os’ option to be enabled. Either way.. now works as advertised and resumes from sleep sub-second and closing the cover sends it to sleep.

So I did this..

C:\> bcdedit /set hypervisorlaunchtype off
The operation completed successfully.

Then (note that the GUIDs will be different on your machine)

C:\>bcdedit /copy {current} /d "Hyper-V Enabled"
The entry was successfully copied to {ff-23-113-824e-5c5144ea}.
C:\>bcdedit /set {ff-23-113-824e-5c5144ea} hypervisorlaunchtype auto
The operation completed successfully.

Also then went into advanced settings and changed default start-up delay from 30 seconds to 5.

Anyhow.. interesting!

Thursday, July 31, 2014

Failure to load packages creating an MVC project

Whenever I create a new MVC project, I am getting an error loading various packages for Powershell, entity framework and Jquery.

The error: The following packages failed to install from 'C:\Program Files\Microsoft ASP.NET\ASP.NET MVC 5\Packages'

I noticed a reference looking for C:\Program Files (x86)\7-Zip\7z.exe, which is pretty strange and subsequently found that 7Zip was installed in the “c:\program files” hive and not in the x86 one. I copied the 7zip folder to the x86 folder structure and then restarted Visual Studio. Now it works as expected.

I can only surmise that by installing 7Zip i have messed with the natural order of things somehow. Either way, copying to the x86 folder fixed things for me.

Something to remember if you get the same issue.

Matt

p.s. i haven’t had this issue on my Windows 7 box but experienced this on the Windows 8 ‘beta’ image i am currently testing for rollout at work. I don’t remember if i installed 7Zip myself or if it was already installed. I have a sneaky suspicion it was already there and maybe the directory it was installed to was incorrect?

Friday, September 27, 2013

Log Parser Studio

If you have ever used Log Parse (go try it if you haven’t) then you know it is a really powerful for obtaining valuable information from IIS, Exchange and other logs. Essentially you use SQL-like queries to query one or more logs and return data and even charts. These sql scripts can be  run from the command line or saved as files. The only thing missing is a GUI to front-end Log Parser and a library of scripts. Enter “Log Parser Studio”!

Log Parser Studio gives you the following features:

  • Store all queries in one location with informative descriptions
  • Edit and create new queries and then save them for later
  • Search for queries
  • Import and export from the library
  • Execute queries
  • Create and run batches of queries (which will run multi-threaded)
  • Scheduling of queries to run unattended (automation)
  • Supports various keyboard short-cuts.

Supported Input Types

Full support for W3SVC/IIS, CSV, HTTP Error and basic support for all built-in Log Parser 2.2 input formats. In addition, some custom written LPS formats such as Microsoft Exchange specific formats that are not available with the default Log Parser 2.2 install.

lps1

Query Library

lps2

Edit and results screen

 

Go get LPS now! (needs Log Parser also.)

Monday, August 12, 2013

Open multiple excel documents in different instances of excel

default functionality for excel will open all new spread sheets in the same instance of excel. this is a special pain when you need to copy or compare spread sheets. One work-around is to open a new instance of excel and then do a file open, however this is tedious.

The solution is modify the registry to give you a new option in the right-click context menu for excel files to open these in a new instance of excel. (Cudos to http://www.online-tech-tips.com/ms-office-tips/how-to-open-a-new-instance-of-excel-2007-workbooks/ for the original article on how to do this for excel 2007)

context

Do this by putting the following code into a text file and then renaming the text file to have a .reg file extension. Backup your registry and then run the reg file. This will add the context menu option to ‘Open in New Excel Instance’.

This should work for Office 2010 and Office 2007 excel files. The code below is setup to open excel 2010 32bit on a 64bit OS. If you are running the 64bit version of office or running a 32bit OS then you need to remove any instances of “ (x86)” from the script. If you are running a different version of office than 2010 then you need to make other changes. (I’m not documenting these here for now).

So, you go from this:

oneinstance

To this:

dualexcel

The default functionality for opening excel documents is not be changed here. We are just adding the context menu item. I have tested this on Windows 7 64 and Windows XP 32bit, both running Office 2010 32bit.

DISCLAIMER: There is NO support for this and you make any registry changes AT YOUR OWN RISK.

Here’s the registry script. Enjoy!

Matt

 

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Excel.Backup\shell\Open_in_New_Excel_Instance]
@="Open in New Excel Instance"

[HKEY_CLASSES_ROOT\Excel.Backup\shell\Open_in_New_Excel_Instance\command]
@="\"C:\\Program Files (x86)\\Microsoft Office\\Office14\\EXCEL.EXE\" \"%1\""

[HKEY_CLASSES_ROOT\Excel.OpenDocumentSpreadsheet.14\shell\Open_in_New_Excel_Instance]
@="Open in New Excel Instance"

[HKEY_CLASSES_ROOT\Excel.OpenDocumentSpreadsheet.14\shell\Open_in_New_Excel_Instance\command]
@="\"C:\\Program Files (x86)\\Microsoft Office\\Office14\\EXCEL.EXE\" \"%1\""

[HKEY_CLASSES_ROOT\Excel.Sheet.14\shell\Open_in_New_Excel_Instance]
@="Open in New Excel Instance"

[HKEY_CLASSES_ROOT\Excel.Sheet.14\shell\Open_in_New_Excel_Instance\command]
@="\"C:\\Program Files (x86)\\Microsoft Office\\Office14\\EXCEL.EXE\" \"%1\""

[HKEY_CLASSES_ROOT\Excel.Sheet.8\shell\Open_in_New_Excel_Instance]
@="Open in New Excel Instance"

[HKEY_CLASSES_ROOT\Excel.Sheet.8\shell\Open_in_New_Excel_Instance\command]
@="\"C:\\Program Files (x86)\\Microsoft Office\\Office14\\EXCEL.EXE\" \"%1\""

[HKEY_CLASSES_ROOT\Excel.SheetBinaryMacroEnabled.14\shell\Open_in_New_Excel_Instance]
@="Open in New Excel Instance"

[HKEY_CLASSES_ROOT\Excel.SheetBinaryMacroEnabled.14\shell\Open_in_New_Excel_Instance\command]
@="\"C:\\Program Files (x86)\\Microsoft Office\\Office14\\EXCEL.EXE\" \"%1\""

[HKEY_CLASSES_ROOT\Excel.SheetMacroEnabled.14\shell\Open_in_New_Excel_Instance]
@="Open in New Excel Instance"

[HKEY_CLASSES_ROOT\Excel.SheetMacroEnabled.14\shell\Open_in_New_Excel_Instance\command]
@="\"C:\\Program Files (x86)\\Microsoft Office\\Office14\\EXCEL.EXE\" \"%1\""

[HKEY_CLASSES_ROOT\Excel.Template\shell\Open_in_New_Excel_Instance]
@="Open in New Excel Instance"

[HKEY_CLASSES_ROOT\Excel.Template\shell\Open_in_New_Excel_Instance\command]
@="\"C:\\Program Files (x86)\\Microsoft Office\\Office14\\EXCEL.EXE\" \"%1\""

[HKEY_CLASSES_ROOT\Excel.Template.8\shell\Open_in_New_Excel_Instance]
@="Open in New Excel Instance"

[HKEY_CLASSES_ROOT\Excel.Template.8\shell\Open_in_New_Excel_Instance\command]
@="\"C:\\Program Files (x86)\\Microsoft Office\\Office14\\EXCEL.EXE\" \"%1\""

[HKEY_CLASSES_ROOT\Excel.TemplateMacroEnabled\shell\Open_in_New_Excel_Instance]
@="Open in New Excel Instance"

[HKEY_CLASSES_ROOT\Excel.TemplateMacroEnabled\shell\Open_in_New_Excel_Instance\command]
@="\"C:\\Program Files (x86)\\Microsoft Office\\Office14\\EXCEL.EXE\" \"%1\""

[HKEY_CLASSES_ROOT\Excel.Workspace\shell\Open_in_New_Excel_Instance]
@="Open in New Excel Instance"

[HKEY_CLASSES_ROOT\Excel.Workspace\shell\Open_in_New_Excel_Instance\command]
@="\"C:\\Program Files (x86)\\Microsoft Office\\Office14\\EXCEL.EXE\" \"%1\""

[HKEY_CLASSES_ROOT\Excel.OpenDocumentSpreadsheet.12\shell\Open_in_New_Excel_Instance]
@="Open in New Excel Instance"

[HKEY_CLASSES_ROOT\Excel.OpenDocumentSpreadsheet.12\shell\Open_in_New_Excel_Instance\command]
@="\"C:\\Program Files (x86)\\Microsoft Office\\Office14\\EXCEL.EXE\" \"%1\""

[HKEY_CLASSES_ROOT\Excel.Sheet.12\shell\Open_in_New_Excel_Instance]
@="Open in New Excel Instance"

[HKEY_CLASSES_ROOT\Excel.Sheet.12\shell\Open_in_New_Excel_Instance\command]
@="\"C:\\Program Files (x86)\\Microsoft Office\\Office14\\EXCEL.EXE\" \"%1\""

[HKEY_CLASSES_ROOT\Excel.Sheet.8\shell\Open_in_New_Excel_Instance]
@="Open in New Excel Instance"

[HKEY_CLASSES_ROOT\Excel.Sheet.8\shell\Open_in_New_Excel_Instance\command]
@="\"C:\\Program Files (x86)\\Microsoft Office\\Office14\\EXCEL.EXE\" \"%1\""

[HKEY_CLASSES_ROOT\Excel.SheetBinaryMacroEnabled.12\shell\Open_in_New_Excel_Instance]
@="Open in New Excel Instance"

[HKEY_CLASSES_ROOT\Excel.SheetBinaryMacroEnabled.12\shell\Open_in_New_Excel_Instance\command]
@="\"C:\\Program Files (x86)\\Microsoft Office\\Office14\\EXCEL.EXE\" \"%1\""

[HKEY_CLASSES_ROOT\Excel.SheetMacroEnabled.12\shell\Open_in_New_Excel_Instance]
@="Open in New Excel Instance"

[HKEY_CLASSES_ROOT\Excel.SheetMacroEnabled.12\shell\Open_in_New_Excel_Instance\command]
@="\"C:\\Program Files (x86)\\Microsoft Office\\Office14\\EXCEL.EXE\" \"%1\""

[HKEY_CLASSES_ROOT\Excel.Template\shell\Open_in_New_Excel_Instance]
@="Open in New Excel Instance"

[HKEY_CLASSES_ROOT\Excel.Template\shell\Open_in_New_Excel_Instance\command]
@="\"C:\\Program Files (x86)\\Microsoft Office\\Office14\\EXCEL.EXE\" \"%1\""

[HKEY_CLASSES_ROOT\Excel.Template.8\shell\Open_in_New_Excel_Instance]
@="Open in New Excel Instance"

[HKEY_CLASSES_ROOT\Excel.Template.8\shell\Open_in_New_Excel_Instance\command]
@="\"C:\\Program Files (x86)\\Microsoft Office\\Office14\\EXCEL.EXE\" \"%1\""

[HKEY_CLASSES_ROOT\Excel.TemplateMacroEnabled\shell\Open_in_New_Excel_Instance]
@="Open in New Excel Instance"

[HKEY_CLASSES_ROOT\Excel.TemplateMacroEnabled\shell\Open_in_New_Excel_Instance\command]
@="\"C:\\Program Files (x86)\\Microsoft Office\\Office14\\EXCEL.EXE\" \"%1\""

[HKEY_CLASSES_ROOT\Excel.Workspace\shell\Open_in_New_Excel_Instance]
@="Open in New Excel Instance"

[HKEY_CLASSES_ROOT\Excel.Workspace\shell\Open_in_New_Excel_Instance\command]
@="\"C:\\Program Files (x86)\\Microsoft Office\\Office14\\EXCEL.EXE\" \"%1\""

Monday, August 5, 2013

Copy SharePoint list items from one list to another and retain full version history and attachments.

Here’s some ‘rough n ready’ code to perform a copy of all list items from one list to another. It will retain all version history, dates, authors, editors, etc. It will also allow you to copy fields from the source list to the target list where the target list field has changed it’s name (must be of the same data type though). In addition, any file attachments for list items are also migrated. Note that file attachments are not versioned. Make sure the destination list has versioning turned on if the source list has versioning enabled.

What doesn’t this do? it doesn’t copy views (personal or public) and it doesn’t copy any permissions. It is also not very robust code. (it’s just a proof of concept at the moment, but feel free to clean it up!)

anyhow.. this is not production worthy code, but it does work. thought it may be useful to someone down the track. Let me know if you use it! 8)

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace MigrateListItemsAndVersions
{
    class Program
    {

        // ****** Setup parameters *******
        static string siteURL = "http://server/site/";
        static string source = "sourcelistname";
        static string dest = "destinationlistname";
        // this is a mapping dictionary to be used when the fields are different names in the target list. Only list the fields that have changed (must be same type to work!!).
        static Dictionary<string, string> fieldMapping = new Dictionary<string, string>
            {
                {"oldcolname","newcolname"}
            };
        // ****** Setup parameters *******


       
        static void Main(string[] args)
        {

            using (SPSite site = new SPSite(siteURL))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    web.AllowUnsafeUpdates = true;
                    SPList sourceList = web.Lists[source];
                    SPList destList = web.Lists[dest];
                    foreach (SPListItem sourceItem in sourceList.Items)
                    {
                        CopyItem(sourceItem, destList);
                    }
                }
            }
        }

        public static SPListItem CopyItem(SPListItem sourceItem, SPList destinationList)
        {
            SPListItem targetItem = destinationList.Items.Add();
      
            //loop over the soureitem, restore it
            for (int i = sourceItem.Versions.Count - 1; i >= 0; i--)
            {
              
                //set the values into the target list
                foreach (SPField sourceField in sourceItem.Fields)
                {
                    SPListItemVersion version = sourceItem.Versions[i];

                    if ((!sourceField.ReadOnlyField) && (sourceField.InternalName != "Attachments"))
                    {
                        targetItem[Mapper(sourceField.Title)] = version[sourceField.Title];
                    }
                    else if (sourceField.Title == "Created" ||
                        sourceField.Title == "Created By" ||
                        sourceField.Title == "Modified" ||
                        sourceField.Title == "Modified By") {
                            targetItem[sourceField.Title] = version[sourceField.Title];
                    }
                }

                //update the target item and loop over the the next version

                targetItem.Web.AllowUnsafeUpdates = true;
                targetItem.Update();
                targetItem.Web.AllowUnsafeUpdates = false;
            }

            // now check for attachments (not versioned) and copy
            foreach (string fileName in sourceItem.Attachments)
            {
                SPFile file = sourceItem.ParentList.ParentWeb.GetFile(sourceItem.Attachments.UrlPrefix + fileName);
                targetItem.Attachments.Add(fileName, file.OpenBinary());
            }

            targetItem.Web.AllowUnsafeUpdates = true;
            // perform a systemupdate so that a new version is not created
            targetItem.SystemUpdate();
            targetItem.Web.AllowUnsafeUpdates = false;
            return targetItem;
        }

        // updates the output fieldname if the destination list has different fields (must be the same type though!)
        public static string Mapper(string fieldNameIn)
        {
            // if not in the mapping dictionary then use the infieldname as the field to write to.
            string fieldNameOut = fieldNameIn;
            if (fieldMapping.ContainsKey(fieldNameIn)) fieldNameOut = fieldMapping[fieldNameIn];
            return fieldNameOut;
        }
    }
}

Tuesday, March 19, 2013

Connecting to the node package repository behind an authenticated proxy server

If you are going to use node and want to install packages, but are behind an authenticated proxy server, you will likely get errors like ‘ETIMEDOUT’ when you make the call. to get around this, you need to tell node how to authenticate. This is easy with the following command from the dos prompt (running as administrator).

npm config set proxy http://domain\username:password@proxyserver:port

 

for example:

npm config set proxy http://northwind\bloggsj:secretpassword@proxy.northwind.com:8080