Author Archive | jbmurphy

jQuery, SharePoint Web Services and adding thumbnail to a List

We have a SharePoint list with thumbnails attached to the list items. The request was to show a thumbnail of the image that is attached. I believe this can be done via SharePoint designer, but I thought jQuery would be easier. I added a Content Editor WebPart to the top of the page. Next I inserted the jQuery code below. This code queries the SharePoint Web Services for every item (not tested on a large list), and then loops through them. If there is an attachment, jQuery takes the ID and the path to the attachment and replace the ID column (has to the first column) for the item with the tumbnail image.

The tricks were:

  1. The soapEnv has to have “<IncludeAttachmentUrls>TRUE</IncludeAttachmentUrls>”
  2. Finding the right selector to get to the ID column:
$("table.ms-listviewtable tr:has(td.ms-vb2)").find("td:first").filter(function() {
			return $(this).text().toLowerCase() == ID;
			}).html("<img src='" + url[1] + "' width=150 height=100 />");

Here is the rest of the code:

$(document).ready(function() {
querySPWebServices();
});

function querySPWebServices() {
        var soapEnv = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
		<soapenv:Body> \
		<GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
		<listName>Projects</listName> \
		<viewFields> \
		<ViewFields> \
		<FieldRef Name='Title' /> \
        <FieldRef Name='Body' /> \
		<FieldRef Name='ID' /> \
		<FieldRef Name='Attachments' /> \
		</ViewFields> \
		</viewFields> \
		<query> \
		<Query /> \
		</query> \
		<queryOptions> \
		<QueryOptions> \
		<IncludeAttachmentUrls>TRUE</IncludeAttachmentUrls> \
		</QueryOptions> \
		</queryOptions> \
		</GetListItems> \
		</soapenv:Body> \
        </soapenv:Envelope>";

        $.ajax({
        	async: false,
            url: "http://server.name.com/site/_vti_bin/lists.asmx",
            type: "POST",
            dataType: "xml",
            data: soapEnv,
            complete: processResult,
            contentType: "text/xml; charset=\"utf-8\""
        	});
};
function processResult(xData, status) {
	$(xData.responseXML).find("z\\:row").each(function() {
		if ($(this).attr("ows_Attachments") != 0) {
		var url = $(this).attr("ows_Attachments").replace(/#/g, "").split(';');
		var ID = $(this).attr("ows_ID");
		$("table.ms-listviewtable tr:has(td.ms-vb2)").find("td:first").filter(function() {
			return $(this).text().toLowerCase() == ID;
			}).html("<img src='" + url[1] + "' width=150 height=100 />");
		};
	});
};

Countdown Clocks and the MTA

Waiting for the subway this morning, it occurred to me that the MTA should not bother spending millions of dollars on Countdown Clocks. Instead, why not invest in app development for smart phones. Since there will be wifi in the subways, why not work on getting data to people’s devices. No citywide maintenance costs on installed hardware, power , or labor.

Since there will already be an infrastructure in place to handle the pushing of the data to the clocks, why not push it to an app on my phone. Basically shifting the hardware costs of the colcks to the riders. Added benefit: info is available where ever you are, so you can time your arrival.

I am sure I am not the first to think of this, but it occurred to me this morning.

My esxupdate script

I was having problems using update manager on an esx box at a remote site. I needed to install several prerequisite patches before i could get to U5.
I went to : http://www.vmware.com/patch/download/ and found the patches I needed.

So I used lwp-download to download the files(esx does not have wget) like so:

lwp-download http://download3.vmware.com/software/vi/ESX350-200911210-UG.zip
lwp-download http://download3.vmware.com/software/vi/ESX350-200911211-UG.zip
lwp-download http://download3.vmware.com/software/vi/ESX350-200911212-UG.zip
lwp-download http://download3.vmware.com/software/vi/ESX350-200911214-UG.zip
lwp-download http://download3.vmware.com/software/vi/ESX350-200911215-UG.zip
lwp-download http://download3.vmware.com/software/vi/ESX350-200911217-UG.zip
lwp-download http://download3.vmware.com/software/vi/ESX350-200911219-UG.zip
lwp-download http://download3.vmware.com/software/vi/ESX350-200911221-UG.zip
lwp-download http://download3.vmware.com/software/vi/ESX350-200911222-UG.zip
lwp-download http://download3.vmware.com/software/vi/ESX350-200911223-UG.zip

Then I used the following simple bash script:

for i in ESX350-2009*.zip
do
unzip $i
mv {,_}$i
cd ${i%%.*}/
esxupdate --noreboot update
cd /back/to/location/of/patches
mv {,_}${i%%.*}/
done

Microsoft should buy Yelp

Yesterday, the blogs reported that Microsoft has not acquired any companies this year. I think Microsoft should and will buy Yelp. It will add a little “hipness” to Microsoft.

Use IPTables to ban repeated ssh attempts

My logs were getting filled with scripts trying to log in via ssh. I already have “PasswordAuthentication no” so I believe I am safe. I wanted to add a new layer (and keep my logs cleaner). I added the following to my iptables config. Anyone with more than 4 connections in 60 seconds is banned:

:SSHAUTOBAN - [0:0]
. . . 
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j SSHAUTOBAN
. . . 
-A SSHAUTOBAN -m recent --set --name SSH
-A SSHAUTOBAN -m recent --rcheck --hitcount 4 --name SSH -j LOG
-A SSHAUTOBAN -m recent --update --seconds 60 --hitcount 4 --rttl --name SSH -j DROP
-A SSHAUTOBAN -m recent --rcheck --name SSH -j ACCEPT
COMMIT

My CEWP JQuery code to play flash files in a Modal

I have Flash files in a Document Library. I wanted to have users click the flash files (swf) and have them open up in a hidden div, rather than opening in a different window. I added the code below to a CEWP:

<script type="text/javascript" src="http://jquery.thewikies.com/swfobject/jquery.swfobject.1-1-1.min.js"></script>
<script>
$(document).ready(function() {
//
$("#popupclose").click(function () {
	$("#popup").Hide();
	$('.media').flash().remove();
	return false;
});
//
$("a[href*='\.swf']").each(function(){
	this.onclick = function(){
	var filetoopen = $(this).attr("href");
	$("#popup").Show;
	$('.media').flash({swf:filetoopen,height:600,width:1000});
	return false;
	};
}); 
//
});
</script>
<style type="text/css">
#popup{  
 display:none;    
 position:absolute;  
 top: 10px; 
 left: 10px;
 background:#FFFFFF;  
 border:2px solid #cecece;  
 z-index:2;  
 font-size:12px;
 }   
</style>
<div id="popup">  
  <a id="popupclose" href="javascript:void()">close</a>
<br/>
  <div class="media" style="vertical-align:top;"></div>
</div>

Simple vbscript (HTA) to install fonts via SCCM

We have a group of users that need the ability to install fonts (.ttf and .otf). They are not administrators for their machines, so we usually go down there and install the fonts using runas. Since advertised SCCM programs can run as system, I can write a script to copy the fonts into the fonts directory. If I mark the package as allow user to intereact and run as administrator, the script will pop for the user to pick the fonts they want to install. Here is my hta code that runs once a button is clicked:

	Set objShell = CreateObject("Shell.Application")
	Set objFolder = objShell.BrowseForFolder (0, "Install Fonts From (Source):", (0))
	If objFolder Is Nothing Then
		window.close
	Else
		Set objFolderItem = objFolder.Self
		objPath = objFolderItem.Path
	End If

	Set objFso = CreateObject("Scripting.FileSystemObject")
	Set objFolder = objFso.GetFolder(objPath)
	bolGotFonts = False
	For each objFile in objFolder.Files
		If objFolder.Files.Count > 0 Then
		  If lcase(objFso.GetExtensionName(objFile.Path))="ttf" OR lcase(objFso.GetExtensionName(objFile.Path))="otf" then
			bolGotFonts = True
			DataArea.InnerHTML = DataArea.InnerHTML & "<input type=""checkbox"" name=""" & objFile.Path & """>" & objFile.Path & "</input><br/>"
		  End if
		End If
	Next
	if bolGotFonts Then DataArea.InnerHTML = DataArea.InnerHTML & "<br/><input id=runbutton  class=""button"" type=""button"" value=""Install Font"" name=""run_button""

This code will popup a browse dialog and put the filenames found in the select directory into the HTA’s DataArea.innerHTML (DataArea is just a <div>) with a checkbox and button to initiate the copy of the files:

SUB InstallFont
    DIM colChkElem, strDriveName, objChkBox
    SET colChkElem = window.document.getElementsByTagName("input")
    FOR EACH objChkBox IN colChkElem
        IF objChkBox.Type = "checkbox" THEN
            IF objChkBox.checked THEN
                strFileName = objChkBox.name
                Set objShell = CreateObject("Shell.Application")
                Set objFolder = objShell.Namespace(FONTS)
                objFolder.CopyHere strFileName
            END IF
        END IF
    NEXT
    DataArea.InnerHTML = ""
END SUB

Seems to work!

I am a CTT+ !!!!

Just got my results from the performance based evaluation. Passed!!!! I am now a CompTIA Certified Technical Trainer (CTT+).

Powered by WordPress. Designed by WooThemes