adventures in technology
Posts tagged sharepoint
Hosts files and the Google Android emulator
Feb 13th
Using the Google Android emulator is a good way to test how a website behaves on Android devices.
Connecting to your local computer
http://10.0.2.2 is the URL to connect to a website hosted on your local computer. localhost or 127.0.0.1 will not work! This is all defined in the documentation on Android emulator networking.
Using a hosts file
The Android emulator will not make use of your local hosts file. This is unfortunate when your website relies on host headers to work correctly (eg. SharePoint). What you need to do is edit the hosts file on the Android emulator image itself.
- start your Android Virtual Device (AVD):
emulator -avd myAvdNameHere -partition-size 128
Located in C:\Program Files (x86)\Android\android-sdk-windows\tools\ on Windows 64bit
Note
The partition-size parameter is needed to expand the image size to prevent an error in step 5. If you try and perform these steps after starting the emulator from the UI you will receive the following error:
failed to copy ‘c:\temp\hosts’ to ‘/system/etc/hosts’: Out of memory - remount the device image as writable:
adb remount
Located in C:\Program Files (x86)\Android\android-sdk-windows\platform-tools\ on Windows 64bit
- save a copy of the existing hosts file to a temporary location on your host computer:
adb pull /system/etc/hosts c:\temp
- edit the hosts file adding an entry pointing to your host computer:
127.0.0.1 localhost 10.0.2.2 mytesthost
- save the edited hosts file to your Android emulator:
adb push c:\temp\hosts /system/etc
You can now browse to your entered hostname in the Android browser.

SharePoint 2010 jQuery compatibility errors – cmssitemanager.js
Jan 26th
Recently I used a site collection scoped feature to add jQuery support to a SharePoint 2010 site collection. As documented on countless blogs, I used custom action XML similar to the following:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
ScriptSrc="JqueryCustomAction/jquery-1.4.2.min.js"
Location="ScriptLink"
Sequence="100">
</CustomAction>
</Elements>
Everything seemed to work as intended. Only later did I notice strange JavaScript errors in the SharePoint interface. The most common errors were in a file called cmssitemanager.js when using the Asset Picker dialog as part of a publishing site:
It turns out that SharePoint 2010 has JavaScript that registers a global function named “$”. This conflicts with the same global function which is registered by jQuery and is used as shorthand for the various jQuery functions.
My very quick solution was to reference a second JavaScript file in my custom action. This JavaScript file disables the “$” shorthand function for jQuery. This fixes all the compatibility issues with the only downside being that you now have to replace “$” with “jQuery” when referring to jQuery globally.
Updated script references:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
ScriptSrc="JqueryCustomAction/jquery-1.4.2.min.js"
Location="ScriptLink"
Sequence="100">
</CustomAction>
<CustomAction
ScriptSrc="JqueryCustomAction/jquery-noconflict.js"
Location="ScriptLink"
Sequence="105">
</CustomAction>
</Elements>
No conflict JavaScript:
// this puts jquery into no conflict mode which will remedy conflicts caused by jQuery when used // with certan publishing features jQuery.noConflict();
Below is a minimal Visual Studio 2010 solution that contains a site collection scoped jQuery feature.