Friday, August 3, 2012

JQuery AJAX Access of SharePoint Web Services for iPad, iDevices

JQuery makes it fairly easy to access SharePoint lists using JavaScript and AJAX calls.  This is helpful when pulling information from one site to another, or when special formatting is required.
There are plenty of blog posts out there with the standard scripts, but it turns out that they fail on the iPad. Doing some research it looks like the iDevices don't return the responseXml from the AJAX call, even if xml is specified as the format. Luckily it does return the data as a string in responseText, and with a change to the code you can convert this to XML.

function isAppleDevice(){
                    return (          
                        (navigator.userAgent.toLowerCase().indexOf("ipad") > -1) ||
                        (navigator.userAgent.toLowerCase().indexOf("iphone") > -1) ||
                        (navigator.userAgent.toLowerCase().indexOf("ipod") > -1)
                    );       
}

function GetLinksData()
{
                var soapPacket = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>
                   <soapenv:Body>
                                <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>
                                <listName>LISTNAME</listName>
                                </GetListItems>
                   </soapenv:Body>
                  </soapenv:Envelope>";
                jQuery.ajax({
                  url: "SITEURL/_vti_bin/lists.asmx",
                  type: "POST",
                  dataType: "xml",
                  data: soapPacket,
                  complete: processLinksResult,
                  contentType: "text/xml; charset="utf-8""
                });
}

function processLinksResult(xData, status) {              
                // prep xml
                var xmlString;
                if (isAppleDevice()) {  // fix for iDevices
                                var myxml = xData.responseText;
                                myxml = $(myxml);
                                var oSerializer = new XMLSerializer();
                                xmlString = oSerializer.serializeToString(myxml[1]);
                } else {
                                xmlString = xData.responseXML;
                }

              
                jQuery(xmlString).find("z\:row").each(function() {
                        alert($(this).attr("ows_Title"));
              
                   });

}

Wednesday, December 7, 2011

Microsoft Office Picture Manager and SharePoint 2010

The Microsoft Office Picture Manager is an image editing and management application that comes with Microsoft Office. It integrates with SharePoint Picture Libraries, allowing you to upload images, edit images, and send images into other Office Applications.

The application uses the sharepoint imaging.asmx web service in SharePoint 2010 to access files. When using the "Send To" command in a Picture Library it will use CheckSubwebAndList, GetItemsByIds, and Download operations to retrieve the image.

The Picture Library uses the IMGLIB.js javascript file. Clicking "Send To" fires off the SendImages() function, which then fires off _SendImages() follwed by SendImagesCore() and finally StartOIS(). Together these functions find the images and library, verify that IE is being used, then kick off the ois.exe application using the OISCTRL.OISClientLauncher Active X Control with the sendto parameter.

Because of the use of the imaging.asmx web service, a Picture Library is required for SharePoint integration with the Microsoft Office Picture Manager.

Wednesday, June 22, 2011

Search Custom User Properties

In SharePoint 2007 if you created a custom User Property and set it to be indexed, it would automatically be used in People searches. This is not the case in SharePoint 2010.

To use a new custom User Property in search in SharePoint 2010 you must at a minimum add it to the "ContentsHidden" Metadata Property.

First run a crawl to put the new property into the index.
In Search go to Metadata Properties
Find and Edit the ContentsHidden property.
Click on Add Mapping.
Filter for the "People" category and find your new property
Click OK.
You may need to run another crawl, but you can now find people using this new property

Tuesday, November 30, 2010

Image Content Type Thumbnails in 2010 Search Results

These changes will allow the SharePoint 2010 Search Results to display the thumbnail for Images stored in an Asset Library. While the thumbnails exist in SharePoint, for some reason they are not automatically displayed or easy to get to.

You can make these changes in the Search Service Application under Federated Locations/Display Information, or by modifying the Core Search Results web part in the search results.

Step 1
In the Search Service Application under Metadata Properties set up the following new managed properties, then run a full crawl

For Content Type (for some reason you cannot access the default ContentType managed Property) set up one that uses the same mappings
ContentTypeforSearch Mappings= Basic:5(Text), ows_ContentType(Text)

To get the Image File Information you'll need the URL. Despite this being mapped to something called "Thumbnail On Form" it is not the Thumbnail URL, but instead the main Image URL.
ImageFileURL Mappings= ows_ThumbnailOnForm(Text)

Step 2
After running a full crawl, add these 2 new properties to the "Columns" of the search results.

Step 3
Add the following template near the top of the XSL document, such as under the rows of xsl:param

<!-- Return the text after the last occurrence of a delimiter -->
<xsl:template name="string-find-last-text">
<xsl:param name="text" />
<xsl:param name="delim" />
<xsl:choose>
<xsl:when test="contains($text, $delim)">
<xsl:call-template name="string-find-last-text">
<xsl:with-param name="text" select="substring-after($text,$delim)" />
<xsl:with-param name="delim" select="$delim" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>

Step 4
Finally add a result format that will display the thumbnail image
Just above the following line:
<xsl:when test="string-length(picturethumbnailurl) &gt; 0 and contentclass[. = 'STS_ListItem_PictureLibrary']">

Add this additional xls "when" section for Images from an Asset Library (ListItem_851)

<xsl:when test="contenttypeforsearch[. = 'Image'] and contentclass[. = 'STS_ListItem_851']">

<xsl:variable name="imagefilename">
<xsl:call-template name="string-find-last-text">
<xsl:with-param name="text" select="imagefileurl" />
<xsl:with-param name="delim" select="'/'" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="imageurlroot">
<xsl:value-of select="substring-before(imagefileurl,'/')" />
</xsl:variable>
<xsl:variable name="siterootname">
<xsl:value-of select="substring-before(url,$imageurlroot)" />
</xsl:variable>
<xsl:variable name="thumbnailfilenameextension">
<xsl:text>.</xsl:text>
<xsl:call-template name="string-find-last-text">
<xsl:with-param name="text" select="$imagefilename" />
<xsl:with-param name="delim" select="'.'" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="thumbnailpath">
<xsl:value-of select="$siterootname" />
<xsl:value-of select="substring-before(imagefileurl,$imagefilename)" />
<xsl:text>_t/</xsl:text>
<xsl:value-of select="substring-before($imagefilename,$thumbnailfilenameextension)" />
<xsl:text>_</xsl:text>
<xsl:value-of select="substring-after($thumbnailfilenameextension,'.')" />
<xsl:text>.jpg</xsl:text>
</xsl:variable>


<div style=" padding-top: 2px; padding-bottom: 2px;">
<div class="srch-picture1">
<img src="/_layouts/images/imageresult_16x16.png" />
</div>
<div class="srch-picture2">
<img class="srch-picture" src="{$thumbnailpath}" alt="" /><xsl:value-of select="$thumbnailfilenameextension" />
</div>
<span><ul class="srch-picturetext">
<li class="srch-Title2 srch-Title5">
<a href="{$url}" id="{concat('CSR_',$id)}" title="{title}">
<xsl:choose>
<xsl:when test="hithighlightedproperties/HHTitle[. != '']">
<xsl:call-template name="HitHighlighting">
<xsl:with-param name="hh" select="hithighlightedproperties/HHTitle" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise><xsl:value-of select="title"/></xsl:otherwise>
</xsl:choose>
</a>
</li>

<li>
<xsl:if test="string-length(picturewidth) &gt; 0 and string-length(pictureheight) &gt; 0">
<xsl:value-of select="$Size" />
<xsl:value-of select="picturewidth" />
<xsl:value-of select="$Multiply" />
<xsl:value-of select="pictureheight" />

<xsl:if test="string-length(size) &gt; 0">
<xsl:if test="number(size) &gt; 0">
<xsl:text disable-output-escaping="yes">&#8195;</xsl:text>
<xsl:choose>
<xsl:when test="round(size div 1024) &lt; 1"><xsl:value-of select="size" /> Bytes</xsl:when>
<xsl:when test="round(size div (1024 *1024)) &lt; 1"><xsl:value-of select="round(size div 1024)" />KB</xsl:when>
<xsl:otherwise><xsl:value-of select="round(size div (1024 * 1024))"/>MB</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:if>
</xsl:if>

<xsl:if test="string-length(datepicturetaken) &gt; 0">
<xsl:text disable-output-escaping="yes">&#8195;</xsl:text>
<xsl:value-of select="$PictureTaken" />
<xsl:value-of select="datepicturetaken" />
</xsl:if>

<xsl:if test="string-length(author) &gt; 0">
<xsl:text disable-output-escaping="yes">&#8195;</xsl:text>
<xsl:value-of select="$Authors" />
<xsl:value-of select="author" />
</xsl:if>

<xsl:if test="string-length(write) &gt; 0">
<xsl:text disable-output-escaping="yes">&#8195;</xsl:text>
<xsl:value-of select="$Date" />
<xsl:value-of select="write" />
</xsl:if>

</li>

<li>
<span class="srch-URL2" id="{concat($currentId,'_Url')}">
<xsl:choose>
<xsl:when test="hithighlightedproperties/HHUrl[. != '']">
<xsl:call-template name="HitHighlighting">
<xsl:with-param name="hh" select="hithighlightedproperties/HHUrl" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="url"/>
</xsl:otherwise>
</xsl:choose>

</span>
</li></ul>
</span>
</div>
<div class="srch-clear">
<img alt="" src="/_layouts/images/blank.gif" />
</div>
</xsl:when>

Thursday, July 29, 2010

Picture Library vs Asset Library

SharePoint 2010 introduces the Asset Library which is similar to the Picture Library. In addition to storing pictures the Asset Library also stores video and audio. If you are trying to decide between the two for picture storage it can be fairly confusing. This post will try to capture some of the differences between the two in terms of storing pictures.
Note: So far the Asset Library is underwhelming in terms of image storage. Lack of Search support and Office integration make this library not much more than a Document Library with a custom set of Content Types. There may be more improvements on the back end for Asset Libraries, especially for video streaming, that aren't covered here.

The Picture Library does not have the ribbon toolbar. The Asset Library does. The Picture Library toolbar is one of the few places that still has a 2007 style toolbar.

Uploading Multiple Documents to a Picture Library uses Microsoft Office Picture Manager and only displays your "My Pictures" folder. You cannot navigate to other locations on your network without first adding a Picture Shortcut.
Uploading Multiple Documents to an Asset Library uses the standard Office document uploader that is the same one used in a Document Library. You can browse your entire network by default.

Selecting a picture and choosing "Send To" in a Picture Library uses the Microsoft Office Picture Manager and will let you put the image right in an Office document (PowerPoint, etc)
Selecting a picture and choosing "Send To" in an Asset Library only lets you send to another SharePoint Site or to create a Document Workspace.
Note: attempts to add the Microsoft Office Picture Manager features to an Asset Library have been unsuccessful. It will only connect to Picture Libraries

Picture Libraries have a View Slide Show option.
Asset Libraries do not have an easy way to view slide shows.

Picture Libraries have a web service at /_vti_bin/imaging.asmx that includes a number of useful operations including Download and ListPictureLibrary.
Asset Libraries cannot use this web service.

The Picture Library uses the Picture Content Type.
The Asset Library uses the Image Content Type.
These content types have similar fields.
Both have Name, Title, Preview, Keywords, Comments, Date Picture Taken, and Picture Size fields.
The Picture Content Type also has a Preview Image URL field not found in the Image Content Type.
The Image Content Type also has Author and Copyright fields not found in the Picture Content Type.
The Content Class returned for Picture Libraries in Search is STS_ListItem_PictureLibrary

Both libraries will automatically generate thumbnails of the pictures that are uploaded. Both name and store these thumbnails the same way.
Picture Library images will show the thumbnail in searches, while Asset Library images will not.
Note that I've added a blog post on how you can get the thumbnails for Asset Library images in your search results.
Digging deeper, the ows_EncodedAbsThumbnailUrl(text) field, which is mapped to the PictureThumbnailURL field that is used in search is empty for the Asset Library search results. This is likely related to the Picture Content Type having a Preview Image URL field that the Image Content Type does not have. Still, the EncodedAbsThumbnailUrl does exist as a field when browsing All Assets of the Asset Library using a CAML viewer. Oddly a field called ows_ThumbnailOnForm does exist, but contains a direct link to the file, and not to a thumbnail.
The Content Class returned for Asset Libraries in Search is STS_ListItem_851

This post will be edited as more differences emerge.