Friday, December 6, 2013

SharePoint 2010 Search - View Properties Link w/ folder and case support - Federated

  • You have SharePoint 2010 Server Standard or Enterprise
  • SharePoint search results provide a link to the document, but no other links
    • Often times a user has to copy and paste the document library url into the address bar and then search for the document in the library to view the properties or kick off a workflow.  This is extremely inconvenient.
  • You would also like a link to the document's View Item (DispForm.aspx) form
  • You would also like a link to the document's Document Library
  • You would like to configure this at the Search Service level so that the links appear in any search center in the farm utilizing the Search Service and also on the OSSSearchResults pages
  • Utilizing code from the following blogs

  • Configure the Search Service in Central Administration as follows
    • Xslt variables and parameters are case sensitive
    • Make sure instructions are followed exactly as written
  • Create 2 managed properties (Metadata Properties in Search Service Application) after your sites have been crawled
    • basic4
      • map to basic:4(text)

        • You have to page to the right after selecting the "basic" group.  It does not show up on the first screen when searching for the crawled properties.  You cannot use the free-text search filter to find this item.
    • listitemid
      • map to ows_ID(integer)
    • Configure Federated Locations in Search Service Application.
      • Click "Local Search Results"
      • Expand "Display Information"
      • Modify the following "Core Search Results Display Metadata" sections
        • Uncheck "Use Default Formatting"
        • Add the following columns to the "Properties" window

          <Column Name="ServerRedirectedURL"/>

          <Column Name="listitemid"/>
          <Column Name="basic4"/>
      • Copy the contents of the XSL into a text editor like Visual Studio or Notepad  
        • Find the IsDesignMode parameter and modify as follows

          <xsl:param name="IsDesignMode">True</xsl:param>

          <xsl:param name="listitemid" />
          <xsl:param name="basic4" />
      • Find the DisplaySize template call and modify as follows

        <xsl:call-template name="DisplaySize">
        <xsl:with-param name="size" select="size" />

        <xsl:call-template name="DisplayViewPropertiesLink">
        <xsl:with-param name="basicFour" select="basic4" />
        <xsl:with-param name="itemUrl" select="url" />
        <xsl:with-param name="siteUrl" select="sitename" />
        <xsl:with-param name="listItemId" select="listitemid" />
        <xsl:with-param name="contentclass" select="contentclass" />

        <img style="display:none;" alt="" src="/_layouts/images/blank.gif"/>

      • Find the end of Stylesheet tag at bottom of document and modify as follows

        <!-- A custom template to display a link to view the properties for a document -->
        <xsl:template name="DisplayViewPropertiesLink">
        <xsl:param name="basicFour" /> <xsl:param name="itemUrl" /> <xsl:param name="siteUrl" /> <xsl:param name="listItemId" /> <xsl:param name="contentclass" /> <!-- Variables to convert siteUrl to lower -->
        <xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
        <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
        <xsl:if test="$contentclass='STS_ListItem_DocumentLibrary'">
        <xsl:when test="contains($basicFour,'http')">
        <xsl:variable name="library" select="substring-before(concat(substring-after(translate($siteUrl, $uppercase, $smallcase), concat(translate($basicFour, $uppercase, $smallcase), '/')), '/'), '/')" />
        <xsl:variable name="viewPropUrl" select="concat($basicFour, '/', $library, '/Forms/DispForm.aspx?id=', $listItemId)" />
        - <a href="{$viewPropUrl}">View Properties</a>
        <xsl:variable name="docLibLoc" select="substring-before(substring-after($itemUrl, concat($siteUrl, '/')), '/')" />
        <xsl:variable name="viewPropUrl" select="concat($siteUrl, '/', $docLibLoc, '/Forms/DispForm.aspx?id=', $listItemId)" />
        - <a href="{$viewPropUrl}">View Properties</a>
        - <a href="{$siteUrl}">
        View Library

        <!-- End of Stylesheet -->

      • Copy the contents of the text file into the "Properties:" textbox, replacing all existing text
      • Hit OK to save the changes
    • You may need to reset the index and run a full crawl to get everything working afterwards
      • Sometimes the Search Centers cache the old XSLT for awhile, so the index reset and possibly an app pool recycle may get it to refresh from the federated location.  Or toggling the Core Results web part on the search center page can work as well.

    Thursday, November 21, 2013

    Attach a Document from SharePoint or Office 365 in Outlook

    • You would like to attach a document to an Outlook email that you have located within SharePoint or Office 365.
    • Note that for internal documents, you should always just link to the document in SharePoint.  Only when sharing with a user who doesn’t have access to your SharePoint site should you send a document as an attachment.
      • You can still use the following to get the link to the document.
    • You don't want to have to download it and then attach it from you local file system first
    • In addition to being able to email attachments directly from MS Word, you can attach the file directly from Outlook using the SharePoint shortcut as follows
    • Right-Click Document Name (This works from anywhere in SharePoint, even search results)
    • Select Copy Shortcut (This puts the Link to the Document in your clipboard)


    • Open the email you wish to attach to
    • Select Attach File 
      • If the recipient does have access to this document in SharePoint, you should just paste the link into the email instead, increasing security and avoiding change management issues.


    • Paste the shortcut into the File name field (Right click and select Paste or use Ctrl-V)


    • Click Insert and finish composing the Email


    Friday, November 15, 2013

    Unable to display this Web Part. SharePoint Designer modified XSLTListViewWebPart

    • A list or library view in the farm has ben modified in SharePoint Designer 2010
    • SharePoint Server 2010
    • An app pool recycle occurs (usually due to automatic nightly app pool restart)
    • You get the "Unable to display this Web Part." error message on any modified view.
    • SP Logs for the correlation id contain the following:
      • Failed to cache field with id "{GUID}", overwrite=0
      • Error while executing web part: System.InvalidCastException: Unable to cast object of type 'System.Reflection.RuntimeMethodInfo' to type 'System.Type'.     at Microsoft.Xslt.MethodCollection.MethodDescription.DeclareDynamicMethod(MethodCollection methodColl)     at Microsoft.Xslt.MethodCollection.CreateDynamicMethods()     at Microsoft.Xslt.MethodCollection.GetMethodInfoInternal(Int32 methodNumber)     at Microsoft.Xslt.MethodCollection.GetMethodInfo(Int32 methodNumber)     at Microsoft.Xslt.STransform.GetCompiledTransform()     at Microsoft.SharePoint.WebPartPages.BaseXsltListWebPart.LoadXslCompiledTransform(WSSXmlUrlResolver someXmlResolver)     at Microsoft.SharePoint.WebPartPages.DataFormWebPart.GetXslCompiledTransform()     at Microsoft.SharePoint.WebPartPages.DataFormWebPart.PrepareAndPerformTransform(Boolean bDeferExecuteTransform)
    • This seems to be a Microsoft bug and only occurs after occasional app pool resets
    • IIS Reset
    • Open the view in SharePoint designer and save

    Thursday, November 14, 2013

    Event Receiver AfterProperties Choice field null bug

    • You are developing an event receiver where you are evaluating the AfterProperties value of an SPFieldChoice column.
    • The column's internal name does not match the display name.
    • The AfterProperties value for this field always return null/nothing.
    • MS oddly decided that this field should utilize the Title instead of the InternalName for the AfterProperties Key.  I have not verified this with the BeforeProperties, but wouldn't be surprised if it's the same.
    • Following is the code I used to workaround this:

    Dim afterObj As Object = properties.AfterProperties(field.InternalName)
    If afterObj Is Nothing AndAlso TypeOf field Is SPFieldChoice Then

      'Microsoft Bug that choice field uses Title instead of InternalName on AFterProperties.
      'Checks for null value first in case MS fixes this later and to reduce overhead.
      afterObj = properties.AfterProperties(field.Title)
    End If

    Tuesday, October 15, 2013

    Projected Lookup Field - Lookup Column Additional Fields Missing

    • You want to project a lookup column (add an additional field or related field).
    • Example:
      • You have a Clients list and a Projects list
      • The Projects list includes a Client lookup column
      • You have a Timesheet list which includes a Project lookup column
      • You would like to project the Client lookup column into the Timesheet view via the Project lookup field.
    • SharePoint 2010 does not support lookup field types as a projected/additional field
      • Some other column types are also not supported
    • Example
      • The Client column will not show up in the "add a column to show each of these additional fields:" checkbox area under the Project lookup column settings, under additional column settings
    • One workaround is to synchronize the fields using SharePoint Designer Workflows with an extra Client Name column in the Projects list.  This requires 1 workflow.
    • This will work with Office 365, SharePoint 2010, or 2013.  Additionally this can be done on SharePoint 2007 except projected columns are not available, so you'd have to sync another column within the Timesheet list as well (meaning 1 more workflow)
    • Note that this workaround will not automatically sync down to the Projects list from the Clients list
      • If you need to sync renames of a client down to the project and timesheet levels, you will need to do one of the following:
        • Create a sandboxed event receiver that will propagate the changes from the Clients list to the Projects list Client Name column
        • Create another workflow on the Clients list or at the site level that updates multiple list items by one of the following means:
          • Acquire or develop a custom workflow action/tool that does this looping
            • Possibly CodePlex
            • Possibly Nintex, Bamboo, K2, or HarePoint
          • SharePoint 2013 REST solution
        • Use a scheduled synchronization utility
    Workaround (Only synchronizes on Projects item change)
    Add a Client Name field (Single line of text) to the Projects list (do not display in view)
    Hide the Client Name field by modifying the Projects list content type
    Now create a workflow on the Projects list to update the field whenever a Project item is changed.  
    In this case the field was required, if it's not required, add in a condition to check for null values.
    Use the Set Field in Current Item action
    Remove the workflow status column from the views on this list.

    Wednesday, October 2, 2013

    FileNotFoundException on SPWeb.GetList

    • You are writing code using the server object model and encounter an intermittant FileNotFound error when using the GetList command after using New Site and OpenWeb(FullURL), passing in a subsite url to OpenWeb. Note that if you add in a delay between OpenWeb and GetList the error does not occur.
    • Apparently Opening the web at a specific location causes the GetList function to behave inconsistantly, throwing a File Not Found exception. Note that we only tried this on SharePoint 2010 in a Visual Studio 2010 console application. This may have been an environment specific issue, so if this solved your problem also, please comment if the environment was the same or different.
    • Pass the web url into the SPSite constructor and call GetWeb with no parameters. Then, when you call SPWeb.GetList(FullUrl) you will not get the FileNotFound exception.

    Tuesday, September 17, 2013

    Office 365 Registration "Partner Information"

    • You are signing up for an Office 365 account and would like to register me as your partner for solution architecture, custom development, integration, and support.  :)
    • This is now known as "Delegated Administration"
    Office 365 Microsoft Partner ID:

    Thursday, September 5, 2013

    Web.Lists, GetLists, and TryGetLists Performance

    • Getting a list or library from a spweb with a large number of lists and libraries. In my test case each spweb had about 90,000 document libraries on sp2010 sp1.
    • You cannot cache the spweb.Lists object across calls. 
      • Ex:  Dynamically looking up a library for each document uploaded via a custom web service or event receiver.
    • Each call to spWeb.Lists.TryGetList(libName) took 13 seconds to process since any access to the Lists collection returns the metadata for all lists in the spweb.
    • Had to recode the solution to access the libraries using the URL rather than the list name, resulting in sub-second processing. spWeb.GetList(listURL)

    List Template Event Receiver Bug

    • You have an event receiver enabled on a specific list via the Receivers ListUrl attribute.
    • If you make a List Template of a list that has been mapped to an event receiver, new lists created from that list template will have the event receiver attached to it regardless of the new URL.
    • Use SharePoint Manager to fix this or disable the event receiver before making the template.

    Wednesday, June 19, 2013

    Database to SharePoint List Synchronization Tools

    MS: Out of the box
    Third Party COTS Synchronization

    Tuesday, June 11, 2013

    BCS BDC external data lookup field migration

    • You want to programmatically set an External Data lookup field
      • Ex: Migrating data into a SharePoint list or library
    • In this case, we used Idera / Metalogix Migration Manager, which does not support External Data fields, nor do they plan on supporting it in the near future
      • This is likely due to the fact that they offer a client only (non-server deployed solution) and haven't figured out how to do this using the remote content deployment APIs
    • The result was that the external data field only displayed correctly in the View Item form and did not populate in the Edit item form or any of the related/projected fields in the view.
    • Luckily I did have access to deploy a server solution, so I developed the following web part to handle the migration
      • If you are using Office 365 or don't have this access then you will need to develop your own solution or need to use a data synchronization solution instead (several vendors make these)
    • In order for this solution to work, you need to add a temporary column to the list that will store the IDs of the field you wish to migrate.  Note that this is not necessarily the display name.
      • In our case we migrated the ID column to a list column named SourceId, ran the tool, then deleted the SourceId column.
    • I utilized code from StackExchange and Jaspers' Weblog along with some forum posts, converting all to VB.Net for aesthetics
    • Download the code
      • The wsp solution file is located in the \SetExternalDataWebPart\bin\Release folder
      • You must enable the feature at the site collection level and add the web part to a page in the subsite that contains the list. 
      • In my test environment this tool updated 25 records every 10 seconds.
    • Notes
      • I found that in addition to setting the display name you also need to set the RelatedField to the BDCIdentity to get the correct value to display in the edit form and to be updateable via the refresh icon.
    // Set the BCS field itself (Display Value)
    listItem[dataField.Id] = dtBDCData.Rows[0][dataField.BdcFieldName].ToString();
    // Set the related field to the BDC Identity
    listItem[dataField.RelatedField] = dtBDCData.Rows[0]["BdcIdentity"].ToString();
    • Some other tips:
      • I had to use the RevertToSelf (BDC Identity) connection to get the refresh to function
      • I did not need to run with elevated or allowunsafeupdates except when debugging permissions.
    • Updated release info:
      • 6/27/2013
        • Added list ID range support to split copies into smaller chunks
          • Uses an SPQuery on ID field.
        • Added refresh interval for regular mid-copy status updates
          • These are actually just auto post backs using an timer control
      • 7/5/2013
        • Fixed refresh bug

    Tuesday, May 28, 2013

    Every SharePoint Team Site should have a OneNote notebook

    Update:  Office 365 and SharePoint now include a OneNote notebook in every Team Site.  Thank you Microsoft for listening!

    In my experience, any "Team Site" should have a document library containing a OneNote team notebook.  My premise is that since a team site is typically created for collaboration, a team notebook is likely the best tool for those needs.  Team sites gutted and used as the base for a custom solution would no longer count towards this premise.  I would also consider Evernote or similar notebook tools as decent alternatives, albeit not as fully featured or integrated.

    Windows 8/10 Tip 
    Make the desktop version of OneNote the default (Not the Metro version) to get the most features

    OneNote 2016 and Office 365 new features

    OneNote Notebook features
    • Continuous Save. No Save Button
    • Automatic track changes / version history
    • Automatic synchronization and offline editing
      • Sync Now (Shift+F9) is an option to refresh quicker when collaborating
    • Simultaneous editing (changes highlighted)
    • Windows-Shift-N desktop shortcut or right click via the control panel
      • Also the Windows-N new side note and Windows-S screen clipping shortcuts
      • Other than Copy/Paste, these should be your most commonly used keyboard shortcuts
    • 1-4 click left/top/right navigation (can go deeper at the section level)
    • Recent notebooks are easily accessible via the Notebook Pane
      • Notebooks are available on the Notebooks Pane on the left nav every time you open OneNote until you remove (Close) the notebook
      • Notebooks can be renamed uniquely to that machine and user
        • Notebook contents however are synchronized across machines and users
      • OneDrive/OneNote.Com/SharePoint/O365 will also maintain a separate list of your recently used notebooks across machines
    • Audio (and video) recording with note taking time stamps
      • Notes taken at any time during the recording can replay the recording at the appropriate time
    • Mobile device support
    • Embedded documents
    • Screen clip tool (Windows-S or Insert screen clip from note page)
    • Embedded links (Linked Web Notes)
      • If researching using a browser, notes taken in OneNote will automatically embed the related URL
      • Copying, pasting, and screenshots will also include the current address from the browser
      • Also works when viewing other OneNote notebooks, PowerPoint, or Word documents
    • Drawing/tablet support (Ink to Text, Ink to Math)
    • Math (Trig/Calculus support )
    • Linked meeting notes from Outlook invitation for quickly accessing meeting notes for scheduled meetings
    • Free form layouts, markups, and drawings
      • Text, drawings, images, etc. can be inserted anywhere on the note page
      • Use to markup a screenshot or document print
    • Dock to desktop and full screen features
      • Docks to side of screen displacing the desktop so that you can take notes while demoing or working
      • Full screen mode removes the notebook navigation and menu items
    • Save to SharePoint or OneNote Online (OneDrive)
      • Notebook sections and pages are saved as folders and files within the document library, so don't be surprised if you see this in explorer view
    • Print to OneNote
      • Quickly markup or take notes on any document source
      • OneNote installs a virtual printer driver on your machine
    • Web based versions of OneNote
    • Share pages and notebooks via Email or Hyperlink (to facilitate notebook adoption)
    • MindMapping Source (Not really specific to OneNote but a nice use)
      • MindMaps are just graphical bulleted lists.  Make the bulleted list in OneNote and then copy the list to your favorite MindMapping tool.  This way you can collaborate with others who don't know or own the MM tool and you can look cool demoing the info.  Note that my whole blog could be converted into a giant mind map. :)
    Additional Features with OneTastic
    • Macros
      • Macroland: prebuilt macros
    • OneCalendar
      • See your notes by date in a calendar
    • Image utilities
      • Crop/rotate images and select OCR'd text
    • Custom styles
      • Like MS Word styles
    • Favorites and pin desktop shortcuts
    When not to use OneNote
    • Final published or printable document
    • Blogging
      • Use Windows Live Writer instead (send to blog is supported but not as good)
      • Drafts in OneNote are ok
    • Heavily formatted content or page oriented layout
      • This is better done in Publisher or Word
      • When copy/pasting or sending to MS Word, bullets may need to be reset and other formatting corrected
        • Highlight the bulleted list and then double click the bullet icon to fix the lists in MS Word
    • Diagramming or presentations
      • Use Visio or PowerPoint
      • Quick hand drawings or draft object drawings are ok
    • Spreadsheets
      • Use SharePoint lists or Excel and embed a link in OneNote
    • Dynamic/sortable/filterable lists, data, or documents
      • Use SharePoint

    Monday, May 13, 2013

    Projected Field in View Item Form

    • You are using Projected Fields (a.k.a. additional columns) from a lookup column in a list or library. 
      • This may be a standard lookup column or a BCS External Data column.
    • You would like these fields to show up on the list/library display (View Item) form.
    • Normally you will only see projected fields in list views configured to display these columns.  For some reason, MS did not include them by default on the display form.
    • Add these fields below the standard item form.
      • The form will continue to be dynamic since the standard Data Form Web Part is still used for all other fields
        • Example: A new column added to the list will automatically show up on this customized display form.
    • Create a New Form in SharePoint Designer on the appropriate list/library.
    • Set the File Name to "DispFormWithAdditionalFields", Type to Display item form, and set as default
    • Temporarily Insert a Display Item Form in the div Below the existing content
    • This will populate the Data Source Details window. Open this window if not already visible. Data view Tools (ribbon) / Options / Data Source Details (Data section)
    • Right click on the Projected Field you wish to display, right click it, then select Copy Item XPath
    • Now delete the temporary Display Item Form. This was just used to populate the Data Source Details window.
    • Insert a SharePoint ListItemProperty control (Insert / Controls / SharePoint) at the same location
    • Right click the control and edit properties.
    • In the Tag Properties window Set the Property property. :)
      • Paste the XPATH copied earlier and delete everything up to the @ sign
        • /dsQueryResponse/Rows/Row/@Exam_x0020_Number_x003a__x0020_Company_Name
        • Change to: Exam_x0020_Number_x003a__x0020_Company_Name
    • Add a column header above or to the left of the new field.
    • Save and Preview in Browser
      (names removed in image)
    • Enjoy!

    Wednesday, May 8, 2013

    SharePoint Migration Tools (Incomplete Article)

    Feature List
    1. Term Stores / Enterprise Keywords
    2. Site Content Types and Site Columns (Taxonomy)
    3. Site Comparison (Differences)
    4. Version History
    5. Maintain modified/created metadata
    6. Metadata bulk editor
    7. Utilize Web Services (No server installs)
    8. Lists and Libraries
    9. Permissions
    10. Users and Groups
    11. SharePoint Designer List and Library workflows
    12. SharePoint Designer Reusable and Site workflows
    13. Flatten folder hierarchy
    14. Office properties to SharePoint properties

    Data and file transfer to SharePoint from the following systems:

    SharePoint: Prior Version, Online (Office 365), or Farm to Farm
    • Idera: SharePoint Migration Suite
      • 2003 - present, SharePoint Online
      • Features: 1, 2, 3, 4, 5?, 6, 7, 8, 9?, 10?, 11?, 12?, 13?, 14?
    • Metalogix
    • AvePoint
    • ShareGate: Migration & Classification
      • Features:  1, 5, 6, 7, 13, 14
        • *1 Features: 2, 8, 9, 10, 11, 12
      • Pricing (11/2012) - Unlimited data - Migration user license
        • $695 for 1 user, $1,295 for *1 Features
        • $4k for 25 users, $4,995 for *1 Features
    OpenText Hummingbird DM or EDOCs DM (part of Enterprise)
    EMC Documentum
    File System