Friday, July 27, 2012

A Word on Content Types

When Editing Content types, make sure you are not editing the core content types for your site collection. Editing "Item", "Document" or "Event" in particular by adding or removing columns and pushing the changes to all content types that depend on these will potentially ruin the functionality of your site. These content types should be locked in a bin, wrapped in chains, put inside a steamer trunk, placed inside a large concrete block and dropped into the Mariana Trench where no-one in your organization will be able to access and modify them.

I mention this as I have just had a small aneurysm after watching 2 weeks of work get blown away because someone modified the "Item" Content type, which ruined the list dependencies I had associated with my InfoPath Form, right as a client was looking at the site.

Thursday, July 26, 2012

SharePoint Calendar Colors with JavaScript


How to add color coded categories to your calendars with JavaScript:

Caveats:

This solution uses Calculated Fields to display colors related to a particular category. The Category column MUST be a choice column - a lookup column will not work as look-up columns are NOT allowed in Calculated Field Column equations.
You must be able to add a Content Editor Web Part to the pages where the calendar will be viewed.

Part 1: Setting up the JavaScript:

  1. Copy the following script into a text file:
    <script>
    _spBodyOnLoadFunctionNames.push('colorCalendarEventLinkIntercept');
    
    function colorCalendarEventLinkIntercept()
    {
      if (SP.UI.ApplicationPages.CalendarNotify.$4a)
      {
        var OldCalendarNotify =
    SP.UI.ApplicationPages.CalendarNotify.$4a;
        SP.UI.ApplicationPages.CalendarNotify.$4a = function ()
          {
            OldCalendarNotify();
            colorCalendarEventLinks();
          }
      }
      if (SP.UI.ApplicationPages.CalendarNotify.$4b)
      {
        var OldCalendarNotify =
    SP.UI.ApplicationPages.CalendarNotify.$4b;
        SP.UI.ApplicationPages.CalendarNotify.$4b = function ()
          {
            OldCalendarNotify();
            colorCalendarEventLinks();
          }
      }
      // future service pack change may go here!
      // if (SP.UI.ApplicationPages.CalendarNotify.???)
    }
    
    function colorCalendarEventLinks()
    {
    
      var divs = document.getElementsByTagName("DIV");
      for (var i=0;i');
        }
        if (divs[i].className.toLowerCase()=="ms-acal-ctrlitem")
        {
          var links = divs[i].getElementsByTagName("A");
          if (links.length==1)
          {
            links[0].href="javascript:colorCalendarEventLinks();void(0);"
          }
        }
      }
    }
    <script>
    
  2. Save the text file to a documents folder on the sharepoint site where you intend to modify the calendar. Make sure it's a folder your customer will have rights to view.
  3. Copy the URL for the text file you uploaded to notepad - you will need to reference this URL later in part 4.

Part 2: Setting Up the Calendar Colors:

  1. Go to this the COLOR-CODING-CALENDAR-LIST site: http://usermanagedsolutions.com/SharePoint-User-Toolkit/Pages/Color-Coding-Calendar-List.aspx
  2. Enter the name of your Category column in the "Choice Column" field
  3. Enter your Categories in the "Choices" field
  4. Enter the name of the column that will be displaying the Calendar Appointment Title text in the "Displayed Column" (usually "Title" or "Name")
  5. Decide how you want the color coding displayed - you can apply it to the text, the background, or the text and the background. If you have any CSS skills you can modify this later.
  6. Leave the rest of the options as is for now and skip down to where the colors are displayed. You'll notice that the category choices you entered in step 3 are displayed here. Use the color pickers to select the colors you want displayed for each category.

Part 3: Setting up the Calendar:

  1. In another TAB or WINDOW, open the Calendar you want to apply the color coding to.
  2. Open the LIST SETTINGS for the Calendar
  3. Create a NEW Column
  4. Name the Column "Color", and set it to "Calculated (calculation based on other columns)"
  5. Open the TAB or WINDOW with the COLOR-CODING-CALENDAR-LIST site.
  6. Copy the code from the GREEN box under the "Paste the following formula in the Color calculated column:" text.
  7. Now open the TAB or WINDOW with your New Calendar Column, and paste the code into the "Formula" box.
  8. Click OK.
  9. Create another NEW Column
  10. Name the Column "Category-Text", and set it to "Calculated (calculation based on other columns)"
  11. Open the TAB or WINDOW with the COLOR-CODING-CALENDAR-LIST site.
  12. Copy the code from the GREEN box under the "Paste the following formula in the calculated column that will be displayed in the list or calendar:" text.
  13. Now open the TAB or WINDOW with your New Calendar Column, and paste the code into the "Formula" box.
  14. Click OK.

Part 4: Fixing the View

  1. In the LIST Settings, under "Views", click the "Create View" link.
  2. Choose the Calendar View type.
  3. Name the View (e.g. "Calendar-Colors")
  4. Under "Calendar Columns", set the "Month View Title:" "Week View Title:" and "Day View Title" to the "Category-Text" column.
  5. Click OK
  6. Make sure you are looking at the new view ("Calendar-Colors" or whatever you named it). You will see tags littering the days where you have appointments set.
  7. EDIT the PAGE (Site Actions > Edit Page)
  8. Add a Content Editor Web Part
  9. Click the little dropdown to "EDIT WEB PART".
  10. In the Content Link Box where it says "To link to a text file, type a URL." Paste the URL to the text file you uploaded in Part 1.
  11. Under Appearance, Set the Chrome Type to "None".
  12. Click OK
The little tag should have disappeared, and you should be seeing your appointments displaying the colors you specified based on their categories.

508 Compliance:

Make sure to provide additional views for people to view your items by category. Additionally you could modify the tags that you paste into the "Category-Text" column to include a "Title" attribute that displays the Category column.

References:

http://usermanagedsolutions.com/SharePoint-User-Toolkit/Pages/Color-Coding-Calendar-List.aspx
http://techtrainingnotes.blogspot.com/2010/06/sharepoint-2010-color-coded-calendars.html
http://www.orbitone.com/en/blog/archive/2010/10/25/calendar-colour-coding-in-sharepoint.aspx

Sunday, May 20, 2012

The Photoshop SDK Plugin Tutorial Fix

I downloaded the Photoshop SDK, which are currently free at the moment, to start creating my own plug-ins.
The SDK comes with a convoluted tutorial, and it took me the better part of the evening to find the one that showed how to compile the provided source code into an .8bf file for windows.

The HTML file in question is "pluginsdk/documentation/html/pgwinplugins.html" and is a travesty of HTML coding. The author neglected to close any <p> tags, and the images are referring to the wrong folder.

The first thing to do is make use of find/replace in your favorite HTML editor and get the images properly linking.

Now assuming you go through the tutorial - it was written for Visual Studio 2005, so half the settings are no longer applicable - and you compile the beast, you will get an error.
"error d8004 /tc requires an argument"

Not being a C++ programmer, or much of a console programmer at all, this drove me nuts.
The answer is NOT in any forum on MSDN. To find the answer I attempted to convert the existing project the tutorial tells you to copy everything from ("dissolve"). In the UpgradeLog.xml, I discovered the following:
<Event ErrorLevel="1" Project="Dissolve" Source="Dissolve.vcproj" Description="VCConvertEngine could not convert attribute CommandLine = cl /I..\..\..\Common\Includes /I..\..\..\..\PhotoshopAPI\Photoshop /I..\..\..\..\PhotoshopAPI\PICA_SP /I..\..\..\Common\Resources /EP /DMSWindows=1 /DWIN32=1 /Tc&quot;%(FullPath)&quot; &gt; &quot;$(IntDir)%(Filename).rr&quot;&#xA;..\..\..\resources\cnvtpipl.exe &quot;$(IntDir)%(Filename).rr&quot; &quot;$(IntDir)%(Filename).pipl&quot;&#xA;del &quot;$(IntDir)%(Filename).rr&quot;&#xA; under VCCustomBuildTool Debug|Win32.">
</Event><Event ErrorLevel="1" Project="Dissolve" Source="Dissolve.vcproj" Description="VCConvertEngine could not convert attribute CommandLine = cl /I..\..\..\Common\Includes /I..\..\..\..\PhotoshopAPI\Photoshop /I..\..\..\..\PhotoshopAPI\PICA_SP /I..\..\..\Common\Resources /EP /DMSWindows=1 /DWIN32=1 /Tc&quot;%(FullPath)&quot; &gt; &quot;$(IntDir)%(Filename).rr&quot;&#xA;..\..\..\resources\cnvtpipl.exe &quot;$(IntDir)%(Filename).rr&quot; &quot;$(IntDir)%(Filename).pipl&quot;&#xA;del &quot;$(IntDir)%(Filename).rr&quot;&#xA; under VCCustomBuildTool Debug|x64.">
</Event><Event ErrorLevel="1" Project="Dissolve" Source="Dissolve.vcproj" Description="VCConvertEngine could not convert attribute CommandLine = cl /I..\..\..\Common\Includes /I..\..\..\..\PhotoshopAPI\Photoshop /I..\..\..\..\PhotoshopAPI\PICA_SP /I..\..\..\Common\Resources /EP /DMSWindows=1 /DWIN32=1 /Tc&quot;%(FullPath)&quot; &gt; &quot;$(IntDir)%(Filename).rr&quot;&#xA;..\..\..\resources\cnvtpipl.exe &quot;$(IntDir)%(Filename).rr&quot; &quot;$(IntDir)%(Filename).pipl&quot;&#xA;del &quot;$(IntDir)%(Filename).rr&quot;&#xA; under VCCustomBuildTool Release|Win32.">
</Event><Event ErrorLevel="1" Project="Dissolve" Source="Dissolve.vcproj" Description="VCConvertEngine could not convert attribute CommandLine = cl /I..\..\..\Common\Includes /I..\..\..\..\PhotoshopAPI\Photoshop /I..\..\..\..\PhotoshopAPI\PICA_SP /I..\..\..\Common\Resources /EP /DMSWindows=1 /DWIN32=1 /Tc&quot;%(FullPath)&quot; &gt; &quot;$(IntDir)%(Filename).rr&quot;&#xA;..\..\..\resources\cnvtpipl.exe &quot;$(IntDir)%(Filename).rr&quot; &quot;$(IntDir)%(Filename).pipl&quot;&#xA;del &quot;$(IntDir)%(Filename).rr&quot;&#xA; under VCCustomBuildTool Release|x64.">
This refers to the "Enter Custom Build Settings for PiPL" step. Item number 6 - where you Click on "Command Line" and create a temporary .rr file. This little guy is giving you the nasty d8004 error in your custom filter.
To fix it, when you go to enter the custom build settings for PiPL, enter the following code in the Command Line:
cl /I..\..\..\Common\Includes /I..\..\..\..\PhotoshopAPI\Photoshop /I..\..\..\..\PhotoshopAPI\PICA_SP /I..\..\..\Common\Resources /EP /DMSWindows=1 /DWIN32=1 /Tc"%(FullPath)" > "$(IntDir)%(Filename).rr"
..\..\..\resources\cnvtpipl.exe "$(IntDir)%(Filename).rr" "$(IntDir)%(Filename).pipl"
del "$(IntDir)%(Filename).rr"
And for the Output, enter the following:
$(IntDir)%(Filename).pipl
When you compile, Visual Studio will be able to locate the necessary resource files, and you'll finally get the .8bf file generated.

Saturday, May 12, 2012

Silverlight Browser Crash

Recently I was working with SharePoint when the browser crashed. I opened my site back up, went to the "create" menu and... BAM! the browser crashed.
Thinking IE was having a "Microsoft Moment" - I opened the site in Firefox. Open the "create" menu and... CRASH!
But Firefox told me something IE didn't - the Silverlight plug-in was misbehaving.
I found this video via Google searches that suggests a number of things to try and get the plug-in to work again.


What ended up working for me was to go to the Silverlight home page (http://www.microsoft.com/silverlight/), save the plug-in to disk, and run it to re-install Silverlight.