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("")
}

5/15/2013

Adding a scrolling list of messages to SharePoint

 

Tested in SP2010, SP2013, Office 365 2013 and should work in SP2007.

I have not offered up a cool SharePoint trick for a while… so here's one that takes a list and turns it into a scrolling "marquee" list like this one:

Release B.2 of the CRM system has been released!

Bugs have been found in B.2, please revert to B.1!

The "Dealing with procrastination" meeting has been rescheduled

Get Started with Microsoft SharePoint Foundation!

This uses the <MARQUEE> tag that may not work in every browser. But according to this page it works in at least these browsers: Chrome 1+, Firefox 7+, Internet Explorer 2, Opera 6+ and Safari 1+.

The code to do this was copied from one of my older tricks "SharePoint: Convert a Links list to a Dropdown list" with only two updates: change the dropdown list to a MARQUEE and to delay load the code so it will also work in SharePoint 2013.

The example below uses an Announcements list, but should work with any list as long as the view displays the "Title (linked to item with edit menu)" column.

How to get the ID of the web part…

The web part's ID has a name something like WebPartWPQ3. To find it:

  1. Use the browser's View, View Source or View Page Source option to display the HTML of the page
  2. Search for a slash followed by the name of the web part:  "/Announcements"
  3. Either read down from what you found looking for something like 'id="WebPartWPQ3"' (the number may be different)  Note: you are not looking for WebPartTitleWPQ3 or other similar names!
  4. Copy everything inside of the quotes, including any extra spaces or periods! Note that 2010 will include the list's name and the list's description while 2007 will only have the list's name.
      summary="Announcements Use this list to track upcoming events, status updates or other team news."

Steps:

  1. Create your Announcements list and add your announcements
  2. Add the announcement list’s web part to the page
  3. Find the name of the web part (see "How to get the ID of the web part" above)
  4. Create a Notepad file:
    1. Copy and paste the JavaScript code from below
    2. Edit the JavaScript to change the line with var LinkList = document.getElementById("WebPartWPQ5") and change "WebPartWPQ5" to your web part name found in step 3 above
    3. Customize the <marquee> tag to set any desired options (see: http://msdn.microsoft.com/en-us/library/aa259539(v=VS.60).aspx)
  5. Upload the Notepad file to a library ("Site Assets" is a good choice)
  6. Right-click the newly uploaded file and select Copy Shortcut (to get the URL to the file)
  7. Add a Content Editor Web Part (CEWP) to the page with the announcements web part, just under the announcements web part
  8. Modify the CEWP and
    1. set its title to whatever you like ("Site News!") (or set its Chrome to none to hide the title)
    2. paste the URL you copied in step 6 into the Content List box
    3. Click OK
  9. Save the page and test it!

Notes:

  • You can customize the <marquee> tag by changing its attributes or wrap it other HTML such as a DIV with a border or background.
  • <marquee> may not work in every browser, but will fall back to list a list of links if it is not supported.
  • There are four lines that start with "MyMarquee.innerHTML", but only one of them is not commented out ("//"). You can uncomment any one of these:
    • text only
    • text with hyperlinks
    • text with hyperlinks that open in a new window
    • text with hyperlinks that open in a SP 2010 style dialog box

 

The Code:

<!-- the MARQUEE tag for the items -->
<!-- customize as needed! –>
<marquee id="TTN_marquee" direction="up" height=48 scrollamount="1"></marquee>


<script type="text/javascript">
// CEWP trick from techtrainingnotes.blogspot.com! 
// http://techtrainingnotes.blogspot.com/2013/05/adding-scrolling-list-of-messages-to.html

// Change the web part name here!!! 
var TTNLinkListName = "WebPartWPQ3";



function TTNgetSPversion()
{  // returns 12 for 2007, 14 for 2010 and 15 for 2013
  var SPversion = "12"; 
  try { SPversion = SP.ClientSchemaVersions.currentVersion.substring(0,2) } 
  catch (e) {}
  return SPversion;
}

function TTNinEditMode()
{
    var editmode="";
    // test for wiki page mode
    try { editmode = document.getElementById("_wikiPageMode").value } 
    catch (e) {}
    if (editmode=="")
    {
      // test for web part page mode
      try { editmode=document.getElementById("MSOSPWebPartManager_DisplayModeName").value } 
      catch (e) {}
    }
    if (editmode=="Edit" || editmode=="Design")
      return true;
    else
      return false;
}

function TTNlist2marquee()
{
  var TTNLinkList = document.getElementById(TTNLinkListName);
  var spVersion = TTNgetSPversion();
  var editmode = TTNinEditMode();

  // hide the list, but only if not in edit mode
  if (TTNLinkList)
  {

    // are we in edit mode?
    var displaymode = "";
    if ( !editmode )
    {
       displaymode = "none";
    }

    // hide the list web part (based on SP version)
    if ( spVersion = 12 ) 
    {
      // 2007 code here
      TTNLinkList.parentNode.parentNode.parentNode.style.display=displaymode;
    }
    else
    {
      // 2010 and 2013 code here
      TTNLinkList.style.display=displaymode;
    }  

    
    //Copy all of the links from the list to the MARQUEE
    var MyMarquee = document.getElementById("TTN_marquee");

    var links = TTNLinkList.getElementsByTagName("A"); // find all of the links
    for ( i=0; i<links.length; i++ ) 
    {
      if (links[i].onfocus)
      {
        if (links[i].onfocus.toString().indexOf("OnLink(this)") > -1)
          { 
            // text only version of the marquee (no links)
            //MyMarquee.innerHTML += links[i].innerHTML + "<br>"; 

            // version with hyperlinks
            MyMarquee.innerHTML += "<a href='" + links[i].href + "'>" + links[i].innerHTML + "</a><br><br>";

            // open the link in a new window
            //MyMarquee.innerHTML += "<a href='" + links[i].href + "' target='newwin'>" + links[i].innerHTML + "</a><br><br>";

            // open the link in a SP 2010 dialog box
            //MyMarquee.innerHTML += "<a href='JavaScript:var options=SP.UI.$create_DialogOptions();options.url=\"" + links[i].href + "&IsDlg=1\";options.height = 400;void(SP.UI.ModalDialog.showModalDialog(options))'>" + links[i].innerHTML + "</a><br><br>";

          }
      }
    }
  }
  else
  {
    alert("Marquee list named '" + TTNLinkListName + "' not found");
  }

}

try {
  // for 2010 and 2013
  ExecuteOrDelayUntilScriptLoaded( TTNlist2marquee, "sp.js" );
}
catch (e) {
  // for 2007
  _spBodyOnLoadFunctionNames.push('TTNlist2marquee');
}

</script>
 
 
.

5/06/2013

So you want to be a SharePoint Developer…

 

In a recent class we started putting together a list of what you need to know to be a well rounded SharePoint developer. The list very quickly got out of hand… but everything in it is required to for some aspect of SharePoint development. You don't need to know all of this if you are focusing on just a part of SharePoint, but not knowing these technologies may result in reinventing the wheel or the creation of things in SharePoint that don't feel like they belong there.

Some of the technologies you will need to know:

  • General web technologies
    • HTML
    • HTML5 (starting with SP 2013)
    • Cascading Style Sheets (CSS)
    • DHTML and working with the DOM
    • XML and XSLT (added by JR!)
    • JavaScript and jQuery
    • Browsers and browser limitations (and how to code around them)
    • web security
  • Microsoft web and development technologies
    • ASP.Net (pretty much everything!)
    • C# and / or Visual Basic .Net
    • AJAX
    • Silverlight (for SP 2010)
    • LINQ
    • ASP.Net 2.0 web parts
    • ASP User Controls
    • Visual Studio
  • General development skills
    • Object oriented development
    • Event driven development
    • Project management
  • SQL Server and SQL querying
  • Web Services in their various flavors
    • .Net 2.0 style SOAP web services
    • Microsoft WCF
    • RESTful services
  • Workflow
    • .NET 3.5 workflow and for 2013, .NET 4.0 workflow
    • Visual Studio workflow development
    • SharePoint Designer declarative workflow development
  • SharePoint
    • End user and site owner skills
    • SharePoint site security
    • SharePoint code related security
    • Event receivers
    • CAML XML and everything it is used with
      • site templates
      • list templates
      • features
      • content types
      • views
      • and much more
    • SharePoint editions and licensing
    • The SharePoint object model and API
    • The SharePoint Client Side Object Model (CSOM)
    • The SharePoint web services
    • The SharePoint architecture
    • SharePoint code deployment options
    • SharePoint web parts
      • connected web parts
      • web part properties panels
    • SharePoint services (knowing what's there and creating new services)
    • Metadata and the metadata API
    • External data connectivity (BCS)
    • Search
      • The Search API
      • iFilter development
  • And for SharePoint 2013
    • SharePoint "app" development
    • writing Azure hosted applications
  • InfoPath
    • General forms development
    • Customizing SharePoint list forms
    • Creating and integrating workflow forms
  • Best practices
    • Web
    • SharePoint
    • JavaScript
    • SQL
    • Web services
    • Documentation
    • Project management
    • Performance testing
    • Testing and deployment
    • Your organization's best practices and SharePoint Governance Plans
  • Tools and resources
  • Also very useful…
    • Microsoft Office development skills
    • PowerShell
    • Visio
    • Mobile Web App Design

Did I miss anything? Post a comment and I will add it to the list.

 

SharePoint Training

As I am a Microsoft Certified Trainer (MCT)I would be remiss if I did not list some of the training resources available through MAX Technical Training! If it's about SharePoint and SharePoint development, MAX has it!

 

SharePoint Certification

These classes are aligned with the Microsoft certifications for SharePoint development:

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.