10/23/2013

Add a SharePoint "New" icon anywhere!

 

Would you like to flag a paragraph or an item in a bulleted list on your home page as "new" and then have the new flag disappear after a certain date? While it would be nice if we could reuse the new item functionality found in SharePoint lists and libraries, we will have to write our own. As we want to keep this as simple as possible we will add the expire date as the image's "Alternate text" attribute, which is easy to do while inserting images into a page.

In a nut shell, the basic steps for your users are:

  1. Edit the page or the web part
  2. Insert the NewFlag.jpg image (you will need to tell them the location or the URL)
  3. Add the expire date as MM/DD/YYYY as the "Alternate Text"

Step 1 – get an image

You can't just use the SharePoint New icon as it is stored as a sprite and not a simple image. We could use a SPAN tag, an IMG tag and a CSS class, but that's too much HTML for our site owners to add each time they want to flag something as new. So we need to find or create an image… you can draw your own in Windows Paint or you could capture the image from a SharePoint page.

Capture the image:

  1. Add a new item to a list or library (so we can see the New icon)
  2. Capture the current screen  (press PrtSc on your keyboard or use a screen capture tool)
  3. Open Windows Paint and paste the screen capture
  4. Use the Select tool and select just the New icon
       image         image(for 2013)         image (for 2010)
  5. In the Paint Home ribbon click Crop and then save the file as NewFlag.jpg
  6. Upload this file to a SharePoint library such as Site Assets, or if you have access to the server, upload the file to c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\Template\Images   (use 12 for 2007, 14 for 2010 and 15 for 2013)

Step 2 – add some JavaScript to the master page

  1. Open your site in SharePoint Designer (2007 for SP 2007, 2010 for SP 2010, etc.)
  2. Find and edit your master page (default.master for 2007, v4.master for 2010 and seattle.master for 2013 – note that the your master may be different!)
  3. Scroll to the end of the master page and find the </body> tag
  4. Add the JavaScript from below, depending on the version, just in front of the </body> tag
  5. Save your master page

Step 3 – test it

  1. Go to the home page of a test site and edit the page
    • for 2010 and 2013 home pages: Site Actions, Edit Page
    • for 2007 basic pages: Site Actions, Edit Page
    • for all web part pages: add a Content Editor Web Part and get it in text edit mode
  2. Add the new text   ("Free laptops until Tuesday!")
  3. 2013
    • Insert the NewFlag.jpg image from wherever you uploaded it next to the new text
      image
    • Set the Alt text to the expire date (i.e. 12/24/2013)
      image
  4. 2010
    • Insert the NewFlag.jpg image and add the expire date as the Alternative Text:
      image
      image
    • For testing, add one image with past date and one with a future date.

      image
  5. Save your changes – expired "new item" flags should now disappear

 

 

The JavaScript code:

For 2007 and 2010

<script type="text/javascript">
// TechTrainingNotes.blogspot.com

function TTNNewFlags()
{
  var TTNimgs = document.getElementsByTagName("img");
  for (var i=0; i<TTNimgs.length; i++)
  {
   if (TTNimgs[i].src)
   {
    if (TTNimgs[i].src.indexOf("NewFlag")>-1)
    {
       var TTNflagdate = new Date(TTNimgs[i].alt);
       if (TTNflagdate < new Date())
       {
         TTNimgs[i].style.display="none";
       }
    }
   }
  }
}

// for 2007 and 2010
_spBodyOnLoadFunctionNames.push("TTNNewFlags()");


</script>

 

For 2013

<script type="text/javascript">
// TechTrainingNotes.blogspot.com

function TTNNewFlags()
{
  var TTNimgs = document.getElementsByTagName("img");
  for (var i=0; i<TTNimgs.length; i++)
  {
   if (TTNimgs[i].src)
   {
    if (TTNimgs[i].src.indexOf("NewFlag")>-1)
    {
       var TTNflagdate = new Date(TTNimgs[i].alt);
       if (TTNflagdate < new Date())
       {
         TTNimgs[i].style.display="none";
       }
    }
   }
  }
}

// for 2013
ExecuteOrDelayUntilScriptLoaded(function () {
      if (typeof asyncDeltaManager != "undefined")
        asyncDeltaManager.add_endRequest(TTNNewFlags);
      else TTNNewFlags();
  }, "start.js");


</script>

Thanks to Daniel Laksana for his tip for delayed load of JavaScript in SP 2013: http://blog.symprogress.com/2013/09/sharepoint-2013-execute-javascript-function-after-mds-load/

 

.

10/21/2013

Cincinnati SharePoint User Group 10/24/13

 

I'll be speaking at the Cincinnati User Group this Thursday, 10/24/13. See you there!


The Cincinnati SharePoint User Group will now be meeting on the 4th Thursday of each month. The next meeting is 10/24/2013. Same location and same time, just a different day!

Speaker: Mike Smith

MVP SharePoint, Senior instructor at MAX Technical Training, Computer professional (computer nut) since 1980, Courseware author, Book author (SharePoint 2007 & 2010 Customization for the Site Owner), Speaker at SharePoint events, toy airplane pilot..

Topic: Using PowerShell, and a web service call or two, to Administer SharePoint Office 365

In this presentation we will combine the recently released SharePoint Online Management Shell PowerShell module, the Microsoft Online Services PowerShell module and a few PowerShell web services calls to management SharePoint Online. By the end of the session we will have a complete script to create a SharePoint classroom or team collaboration environment in the cloud!

We will use the Microsoft Online Services to add users, passwords and manage licenses.

We will use the SharePoint Online Management Shell to create Site Collections, add users and add groups.

We will use web services to create subsites, lists and libraries.

And of course... there will be food, door prizes and networking!

http://www.CincinnatiSPUG.org

9/29/2013

SharePoint - Delete all alerts!

 

Need to clean out all of the alerts from a development or testing system? Here's a PowerShell script to delete alerts. Run at your own risk... This will delete all alerts in all subsites in all site collections in all web applications (including My Sites).

Did I say… "Run at your own risk"?  PowerShell scripts like this one can do real harm on a production system and should only be run on a development or testing system. 

 

So… Run at your own risk…  Smile

This should work in both SharePoint 2010 and 2013.

foreach ($site in Get-SPSite -Limit All) 
{ 
  "Site Collection $site" 
  foreach ($web in $site.allwebs)
  {
     "  Web $web"
     $c = $web.alerts.count
     "    Deleting $c alerts"
     for ($i=$c-1;$i -ge 0; $i--) { $web.alerts.delete($i) }
  }
}

9/28/2013

Unable to retrieve topology component health states

 

Got this error while building a SharePoint 2013 single server install for classroom use:

"Unable to retrieve topology component health states. This may be because the admin component is not up and running."

The error was displayed on the search services administration page in the Search Application Topology section. At the same time the search crawls were stuck in "Starting" and all site searches were failing.

Searching the web found a number of reports of this error and numerous solutions that did not work on my server. Many of the solutions were from the days of the beta releases. I finally found the solution for my server on Marc Molenaar's blog site (http://www.mavention.nl/blog/sp2013-installation-lessons-learned-part-1) and he had a link to TechNet discussion where Paul Stork had the solution… an issue with the search proxy and a fix using PowerShell.  See Marc's article for the PowerShell script.

I now have a working search and all green checkboxes in the Search Application Topology section of the search admin page!

.

9/23/2013

Am I a SharePoint Site Collection Administrator?

 

In my training and consulting I often run into people who are not sure if they are a Site Owner or a Site Collection Administrator.

Go to Site Actions, Site Settings and see if you have a link to "Site collection administrators". If you do, then you are one!  (In SharePoint 2013 the Site Actions link is the "gear" image)

If you don't see the link, don't stop yet… you may be in a subsite. Look for "Go to top level site settings" and if you see it, click it.

    image

Here's the "Site collection administrators" links:

2007:
     image_thumb[24]

2010:
    image_thumb[23]

2013:
    image_thumb[25]

 

Note: You could have Full Control as a Site Owner or be a Site Collection Administrator and still not be able to do everything in your site. Your SharePoint server administrators can block certain features like creating subsites, even if you have Full Control.

 

.

9/13/2013

wssdemo.com has moved

 

I show the wssdemo.com web site in almost every SharePoint class. This week I typed the url into a browser to show the Silverlight Pivot control and only got a 404 Not Found error! Well today I found the the site… it has a new URL and no forwarding from the old URL. The new URL is:

www.SPSDEMO.com

8/02/2013

PowerShell to the rescue (again!)

 

Using PowerShell to replace text in a file.

I have a custom class next week. I need to make a little fix to the lab files… actually 526 .css files and 380 .htm files need to be updated with several fixes in each. Lots of little fixes.

 

How did I know how many files?  PowerShell of course…

(Get-ChildItem *.css –Recurse).count

 

Find and replace some text…

First update was to fix some URLs. I needed to remove a backslash at the start of every "href=" and "src=".  A little PowerShell could also do all of the file edits!

$from = 'href="/'
$to = 'href="'

Get-ChildItem *.htm -recurse |
%{
     $name = $_.fullname; Write-Host $name; (Get-Content $name) |
     %{ $_ -replace $from,$to } |
     Set-Content -path $name –force
}

I wrapped the above line in a function, called it eight times with my eight replacements, and it was done in seconds!

 

Notes:

Find all of the files…

  Get-ChildItem *.htm -recurse

and run some code on each one:

   %{   }

Save the file path to a variable, display the file path and then get the file's contents:

   $name = $_.fullname;
   Write-Host $name;
  (Get-Content $name)

The pipe then has the text to be replaced, so let's do the replace:

   %{ $_ -replace $from, $to }

And write the replaced text out to a file with the same name:

   Set-Content -path $name –force

 

.

6/03/2013

Free SharePoint 2013 Webinar

 

Tomorrow I will be giving a one hour webinar with MAX Technical Training on what's new in SharePoint 2013. This will include both the what's new bullet points, and a lot of little things I've found over the last year or so. Grab a sandwich and join me for a SharePoint lunch and learn!

Tuesday, June 4th from 12-1 pm
   
Reserve Your Webinar Seat Now

What's New in SharePoint 2013 - Features and User Interface

SharePoint 2013 is now in its 5th generation. While 2013 appears to have changed dramatically you will find that it is an interesting mix of unchanged features that you and your users already know, and a lot of new functionality that you will be exploring for the next few years.

In this webinar we will try to reduce the "fear of change" by showing you what has not changed while also showing how many new features and changes will add value to your world of information management and sharing.

Our presenter, Mike Smith, is a SharePoint Microsoft Most Valuable Professional (MVP), Microsoft Certified Trainer (MCT), Senior Technical Instructor with MAX Technical Training and author of the book: SharePoint 2007 and 2010 Customization for the Site Owner.   

.image

6/02/2013

SharePoint Versioning Trivia, or maybe a start on a versioning FAQ

 

The number of versions retained is one more than the limit you set. Entering 10 as the version limit will keep up to 11 versions of the item. I guess the current "version" is not counted as a "version".

image

Then maximum number of versions per item is 5000. (at least in SP 2010)

image

We you exceed the version limit the oldest item is immediately discarded. It is not moved to the recycle bin.

Only libraries support Minor or Draft versioning. Lists only support major versions.

The maximum number of draft versions is 511, and you can't change that number. Attempting to create a 512th draft version generates this error:

image

"Keep drafts for the following number of major versions" will automatically discard minor versions of published major versions over the entered limit. Actually… it will keep one less than you probably expect.

image

For example, if the limit is 3 and you have some unpublished drafts, then you will see drafts from the previous 2 published versions plus the current drafts:

image   (click image to enlarge)

Notice that you see 13.1, 14.1, 15.1 and 15.2, but not 12.1. Three sets of drafts as expected. Now let's publish 15.2 into 16.0:

image(click image to enlarge)

Now we only have two sets of drafts, 14.1 and 15.1.

 

Clicking "Delete All Versions" actually deletes all but one version. The latest version is retained.

Reducing the version limit will not automatically delete excess old versions. The excess old versions will be deleted the next time the item is deleted. (You can create a PowerShell script to clean out the excess versions.)

Visitors to the site can see all of the old versions by default. You may want to edit the Read and View Only permissions levels to remove the "View Versions" permission.

Major version numbers are assigned internally using “version number” times 512. You can see this when display a version of a list item. Example of a direct URL: http://intranet /Lists/Announcements/DispForm.aspx?ID=1&VersionNo=1024
No that’s not version 1,024! Version numbers are assigned using “version number” times 512. Version 1 is 512, version 2 is 1024, version 3 is 1536 (i.e. 3 * 512), version 4 is 2048 (i.e. 4 * 512) …

 

Notes for developers and PowerShell scripters:

Versioning related properties of SPListI:

  • .MajorVersionLimit – the "Keep the following number of major versions" field in Versioning Settings
  • .MajorWithMinorVersionsLimit - the "Keep drafts for the following number of major versions" field in Versioning Settings

Versioning related properties of SPListItem:

  • .Versions – a collection of retained versions
  • .Versions.Count
  • .Version[0]  gets the most recent version of the item
  • .Verions[x] where x is .Versions.Count, is the oldest version of the item (i.e. versions are stored in reverse order)
  • .HasPublishedVersion   -  boolean

 

Here's a little PowerShell script that will take the first document (ID=1) in the Shared Documents library and create 10 major versions, each with two minor versions.

# before running this, enable major and minor versioning on the library

# get the web site
$web = Get-SPWeb http://intranet.contoso.com

# publish the first document 10 times
for ($versionsToCreate=0; $versionsToCreate -lt 10; $versionsToCreate++)
{
  # get the document
  $doc = $web.lists["Shared Documents"].getitembyid(1)

  # create two minor versions
  for ($x=0; $x -lt 2; $x++) { $doc.update() }

  # publist the last minor as a major version
  $doc.File.publish("")
}

Note to spammers!

Spammers, don't waste your time... all posts are moderated. If your comment includes unrelated links, is advertising, or just pure spam, it will never be seen.