8/31/2009

Cincinnati SharePoint User Group Meeting

http://cincyspug.securespsites.com  6:00 PM 9/3/09 at MAX Technical Training

SharePoint -- Externalizing Content BLOBs to a NAS, SAN CAS or to the Cloud 
        Brian Battah, Senior Architect at BlueThread Technologies, will
provide an overview of the performance, security and scalability
benefits of SharePoint BLOB storage. He will also discuss how
BlueThread’s StoragePoint solution can be leveraged to externalize
SharePoint content to different endpoints including Windows Azure BLOB
Storage, EMC Atmos Online, and Amazon S3 Cloud storage.

 

We have a door prize!  WIN A DELL - INSPIRON MINI NETBOOK WITH INTEL® ATOM™ PROCESSOR

8/30/2009

SharePoint: Code Snippets in SharePoint Designer!

Visual Studio has a large number of “canned” blocks of code that can be quickly added to a project using a shortcut key. These are call Snippets. Turns out that SharePoint Designer has them too. But only a few…

Inserting a Snippet:

Click in the code window where you want the Snippet and press Ctrl-Enter (or click Edit, IntelliSense, List Code Snippets):

    image

 

Creating your own Snippets:

You can create your own Snippets either by using a shortcut or by going to Tools and Page Editor Options.

Shortcut:

  1. Select existing text you would like to use for a Snippet
  2. Right-click and select Create Code Snippet

Or go to Tools, Page Editor Options:

    image

 

.

8/26/2009

SharePoint: Change the “No Items” message in a discussion web part

 

Yet another Content Editor Web Part (CEWP) trick…

But you can also add it to the master page!

 

When you create a new team site or add a new discussion list to a site the discussion web part displays a "no items" message. If you would like to change this message all you need is a little JavaScript added to the web part page or to the master page. If you would rather hide this web part anytime there are no discussions then see the previous customization: "Hide a web part with zero rows".

Before:

      image

After:

    image

 

Steps:

Add a Content Editor Web Part to the page with the discussion web part and using the Source Editor button (2007) paste the following JavaScript.  For 2010 or 2007 create a text file in a library with this JavaScript and link to it from the Content Editor Web Part.

<script  type="text/javascript">

function ChangeDiscussionMessage()
{

  var a = document.getElementsByTagName("TD");
  for ( var i=0; i<a.length; i++ )
  {
    if (a[i].className=="ms-vb")
    {
      if (a[i].innerHTML.indexOf("There are no items to show in this view")>-1 &&
          a[i].innerHTML.indexOf("discussion board")>-1)
      {
         a[i].innerHTML = "There are no active discussions";
      }
    }
  }
}

_spBodyOnLoadFunctionNames.push("ChangeDiscussionMessage"); 

</script>
 

.

 

 

.

8/15/2009

SharePoint: Tricks for web part customizers

 

Trick 1: Deleting a bad web part

If you have just added a web part to a page and you get the dreaded error page as a result, add ?Contents=1 to the page’s URL.

    http://……./default.aspx?Contents=1

You can now delete the offending web part.

 

Trick 2: Getting to web parts when there is no “Edit Page” in Site Actions

Add &ToolPaneView=2 to then end of the URL. This example will let you see the web parts on a list’s NewForm page.

   http://……./NewForm.aspx?……..&ToolPaneView=2

 

.

SharePoint: Shortcut keys!

 

Did you know that SharePoint has shortcut keys? Most Windows applications have a standard set of well known shortcut keys. While most web applications do not, SharePoint has a large number of shortcut keys, and a few like the OK and Cancel shortcuts can save you a lot of scrolling up and down the page after each edit..

 

Here are a few samples:

Alt-1 + Enter    Goto Home page (same as clicking Home tab)
Alt-6 + Enter    Help
Alt-l + Enter     Welcome menu
Alt-o                  OK or Create
Alt-c                  Cancel
Alt-s                 Search - move cursor to Search text box

 

For a complete list see:

http://office.microsoft.com/en-us/help/HA101733621033.aspx 

 

 

.

8/09/2009

SharePoint: Missing Content Query Web Part (CQWP)

Many blog articles offer the Content Query Web Part as a solution to a lot of custom web part query problems. But, most users cannot find it as it is only displayed by default in Publishing template sites.

 

To enable the CWQP:

First of all, the CWQP is a MOSS web part and is not available in WSS. WSS users can use SharePoint Designer and the DataView web part to do similar rollups.

You get access to the CWQP you will need to turn on "Office SharePoint Server Publishing Infrastructure" in Site Actions, Site Settings, Site Collection Features (last column). You will then find the CWQP in the Default section of the web parts popup.

 

Enabling "Office SharePoint Server Publishing Infrastructure" will also add:

  • additional lists and libraries: Site Collection Documents, Site Collection Images, Style Library, Content and Structure Reports, Reusable Content, Workflow Tasks
  • new items in Site Actions, Site Settings:
         Removes: Quick Launch, Top Link Bar
         Adds: Navigation, Searchable Columns, Content and Structure, Content and Structure Logs, Variations, Variation lables, Variation logs, Translatable columns
  • new items in Site Actions, Create: Adds: Publishing Site, Publishing Site with Workflow
  • new Web Parts:
       Content Query Web Part
       Summary Link Web Part
       Table of Contents Web Part

One side effect of the above is a big change in the way you edit the Top Link Bar (tabs) and Quick Launch. Both are now maintained in a single option call Navigation, and are called “global navigation” (tabs) and “current navigation” (Quick Launch). There is a bonus though… you can now create dropdowns from the tabs!

 

.

7/31/2009

SharePoint: Run JavaScript based on user rights / permissions

 

There are all kinds of tricks you can do with JavaScript in SharePoint. Sometimes though you only want the JavaScript to run for selected users.

  • If you want to run the JS for only a single site just check the URL for the page name (document.location.href)
  • If you want to run the JS for only a single person just write some JS to retrieve the user’s name from the Welcome menu at the top of the page
  • If you want to run the JS based on the permissions of the user, then you need to use a SharePoint control called: SPSecurityTrimmedControl

Using SPSecurityTrimmedControl

The SPSecurityTrimmedControl cannot be used inside of Content Editor Web Part as it must be processed on the web servers. So, you must add something to the ASPX page or the master page.

 

Here’s an example:

 

<script> var UserHasPermissions=false; </script> <Sharepoint:SPSecurityTrimmedControl runat="server" PermissionsString="ManageWeb"> <script> UserHasPermissions=true; </script> </SharePoint:SPSecurityTrimmedControl>

 

If you put this block of code somewhere on the master page before where you need to run your code then you can use the value UserHasPermissions in the ASPX file. If you put this in the master page before where web parts are loaded then you can use this in your Content Query Web Part JavaScript tricks!

In your JavaScript you only need to check this value:

 

<script> // do something based on permissions if ( UserHasPermissions ) { // add your code here alert("ALERT from SecurityTrimmedControl") } </script>

 

You may want to add several of these tests so you can then have UserHasWebPermissions, UserHasDeletePermissions, UserHasXYZPermissions, etc.

 

More Info:

For more info on SPSecurityTrimmedControl see:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.spsecuritytrimmedcontrol.aspx

There is a list of the permissions strings at the bottom of this article: 
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.spsecuritytrimmedcontrol.permissionsstring%28office.12%29.aspx
These strings are the same permissions found in the SharePoint Permission Levels (Site Actions, Site Settings, Advanced Permissions, Settings, Permission Levels - then add or edit an existing to see the list)

 

And here’s another example to hide “All People” on the People and Groups pages:

If you don't mind editing the application.master, and there is a permission item that can identify the group of users who should see or not see the option then…

Insert the following just before </BODY> in application.master. Modify PermissionsString="ManageWeb" to one of the choices found here that only your desired users have.

<script>
var UserHasPermissions=false;
</script>
<Sharepoint:SPSecurityTrimmedControl runat="server" PermissionsString="ManageWeb">
  <script>
    UserHasPermissions=true;
  </script>
</SharePoint:SPSecurityTrimmedControl>

<script>
if ( !UserHasPermissions )
{
  var x = document.getElementsByTagName("A")
  for (var i=0;i<x.length;i++)
  {
    if (x(i).innerText=="All People")
    {
      x(i).parentNode.style.display="none";
    }
  }
}
</script>

 

 

.

7/25/2009

SharePoint: Change the “Add New” message for a web part

 

A version of this article for SharePoint 2010 is here:
http://techtrainingnotes.blogspot.com/2010/08/sharepoint-2010-change-add-new-item-and.html

 

 

How to change from “Add new announcement”:

   image

to “Click here to add team news”:

   image

 

ID’s used by web parts

Each web part has a different ID. You will need to modify the following code with the needed ID. Note that some lists use the same ID, like Documents and Wikis.

 

Web Part Default message ID for “document.all” in the code below
Announcements Add new announcement "Add new announcement"
Links Add new link "idHomePageNewLink" 
Calendar Add new event "idHomePageNewEvent"
Picture Library Add new picture "idAddPicture"
KPI List Add new item "idAddNewItem"
Tasks Add new item "idAddNewTask"  *
Project Tasks Add new item "idAddNewTask"  *
Document Library Add new document "idAddNewDoc"   *
Wiki Add new Wiki page "idAddNewDoc"   *
Survey Respond to this survey "idNewSurveyResponse"
Discussion Add new discussion "idAddNewDiscuss"

* = Shared with another list

Steps:

  • Add an Content Editor Web Part (CEWP) below the Announcements web part.
  • From the CEWP click Edit and Modify Shared Web Part
  • Click the Source Editor button
  • Paste the following:
<script>
  document.all("Add new announcement").innerHTML="your new text goes here"
</script> 
  • Click OK, then OK, then Exit Edit Mode

If you have more than one web part on the page with the same ID then you need to change the [0] to the number for the web part. 0=first web part, 1=second web part, etc.

document.all("Add new announcement")[0].innerHTML="your new text" 

 

If you want to get rid of the little icon just before text try this:

<script>
  var ttn_x;
  ttn_x=document.all("Add new announcement")
  // replace the text
  ttn_x.innerHTML="Click here to add team news"
  // delete or replace the image
  ttn_x.parentNode.innerHTML = ttn_x.parentNode.innerHTML.replace(/<IMG alt="" src="\/_layouts\/images\/rect\.gif">&nbsp;/,"")
</script>

If you have more than one web part on the page with the same ID then you need to change the [0] to the number for the web part. 0=first web part, 1=second web part, etc.

The image is a fragment of HTML that looks like this:

<IMG alt="" src="\/_layouts\/images\/rect\.gif">&nbsp;

The code above replaces this. JavaScript’s replace command uses regular expressions so you need to escape the “/” and “.” characters.

 

.

7/17/2009

SharePoint: Rotating Pictures, Random Pictures (updated)

 

Yet another update!  People can be such a pest… you keep asking for “captions, for buttons, for Play/Pause… Well I finally took the time to do it. Rather than complicate this post any more, I have the update here:
http://techtrainingnotes.blogspot.com/2010/05/sharepoint-rotating-pictures-random.html

Here’s a what the updated one looks like (without the animation):

image

 

SP 2010 Update: Will this work in SharePoint 2010?  Who cares!  SP 2010 has a new “Picture Library Slide Show web part” that can display random pictures every “x” seconds! (But my new version above is customizable!)

 

Updated to support Firefox and to add an optional hyperlink.

 

Many web sites have pictures that keep changing while the page is displayed. If you were doing ASP.NET development you might use the AdRotator control to do this. You can find some custom web parts that can be installed on your web server to do this.

But… I wanted a way to do this with no C# programming, no server deployment issues and even without SharePoint Designer. This is yet another Content Editor Web Part trick!

 

How this works:

  • Add a picture library and upload some pictures
  • Add a the web part for this new library on your home page
  • Customize the view used by the web part
  • Add a Content Editor Web Part to the same page and paste the HTML and JavaScript code below
  • Sit back and watch!

Options:

When you paste the JavaScript you can set a few options to control the appearance of the images:

  • One is required:
    • The name of the web part
  • The rest are optional:
    • Show in thumbnail size (160 pixels wide) or full size
    • Show in the order found in the web part or random
    • Set how long each picture is displayed
    • Set how long to take to transition between images
    • Set if you would like to make the images clickable to a custom URL

Important note: This has only been tested in Internet Explorer and Firefox 3.5.2 so far. I will try to some testing with other browsers soon.

 

Steps:

  • Create your picture library and upload your pictures
  • If you would like to supply links for the pictures, add a hyperlink column
  • If you would like to filter the list of pictures to be displayed, customize the library to add additional columns to how the filter data. (Event name, department, product, etc)
  • Go to your web part page and add the web part for the new library
  • Important steps:
    • Click Edit, Modify Shared Web Part
    • Optional: In the appearance section give the web part a meaningful name
    • Click Edit the Current View
    • Un-checkmark all of the columns except for “Name (linked to document)”
    • Optional: check a column to use as a custom hyperlink (must be the second column in the view)
    • Optional: Set the sort order
    • Optional: Set filter options to select only the pictures you want displayed
    • Make sure the the list web part view is not using a "Item Limit" less then the number of pictures in the list. (You could just set this to be BIG number).
    • Click OK to save the view changes
    • Click OK to save the web part changes
  • Add a Content Editor Web Part (CEWP) below the picture library web part
  • Click Edit, Modify Shared Web Part
  • Click Source Editor
  • Copy and paste the code from below
  • Click OK for the Source Editor
  • Click OK to save the web part changes
  • Click Exit Edit Mode and see if it works!

The Code:

 

<script>
// another CEWP trick from http://techtrainingnotes.blogspot.com
var pictureWebPartName="Airshow Pictures"; // name of the picture library web part
var showThumbnails = true; //otherwise show full sized images
var randomImg = true; //set to true to show in random order
var useCustomLinks = false; //true to use second column as URL for picture clicks
var RotatingPicturesLoopTime = 5000; //2000 = 2 seconds
var imgToImgTransition = 1.0; //2 = 2 seconds

// don't change these
var selectedImg = 0;
var imgCache = [];
var imgTag;

function RotatingPictures()
{

imgTag = document.getElementById("RotatingImage");
//Find the picture web part and hide it
var Imgs = [];
var x = document.getElementsByTagName("TD"); // find all of the table cells
var LinkList;
var i=0;

for (i=0;i<x.length;i++)
{
if (x[i].title == pictureWebPartName)
{
// tables in tables in tables... ah SharePoint!
LinkList = x[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
// hide the links list web part
// LinkList.style.display="none";
break;
}
}

if (!LinkList)
{
document.all("RotatingImageMsg").innerHTML="Web Part '" + pictureWebPartName + "' not found!";
}

//Copy all of the links from the web part to our array

var links = LinkList.getElementsByTagName("TR") // find all of the rows
var url;
var len;
for (i=0;i<links.length;i++)
{
//if (links(i).id.match("row")!=null)
if (links[i].childNodes[0].className=="ms-vb2")
{
len=Imgs.length
Imgs[len]=[]
Imgs[len][0] = links[i].childNodes[0].childNodes[0].href;
if (useCustomLinks)
{
if (links[i].childNodes[1].childNodes.length>0)
{ Imgs[len][1] = links[i].childNodes[1].childNodes[0].href; }
else
{ Imgs[len][1] = "" }
}
}
}
if (Imgs.length==0)
{
document.all("RotatingImageMsg").innerHTML="No images found in web part '" + pictureWebPartName + "'!";
}
for (i = 0; i < Imgs.length; i++)
{
imgCache[i] = new Image();
imgCache[i].src = Imgs[i][0];
if (useCustomLinks)
{
imgCache[i].customlink=Imgs[i][1];
}
}
RotatingPicturesLoop();
}


// now show the pictures...
function RotatingPicturesLoop()
{
if (randomImg)
{
selectedImg=Math.floor(Math.random()*imgCache.length);
}

if (document.all){
imgTag.style.filter="blendTrans(duration=" + imgToImgTransition + ")";
imgTag.filters.blendTrans.Apply();
}

url=imgCache[selectedImg].src
if (useCustomLinks)
{ RotatingImageLnk.href=imgCache[selectedImg].customlink; }
else
{ RotatingImageLnk.href = url; }

if (showThumbnails)
{
// convert URLs to point to the thumbnails...
// from airshow%20pictures/helicopter.jpg
// to airshow%20pictures/_t/helicopter_jpg.jpg

url = revString(url);
c = url.indexOf(".");
url = url.substring(0,c) + "_" + url.substring(c+1,url.length);
c = url.indexOf("/");
url = url.substring(0,c) + "/t_" + url.substring(c,url.length);
url = revString(url) + ".jpg";
}


imgTag.src = url;
if (document.all){
imgTag.filters.blendTrans.Play();
}
selectedImg += 1;
if (selectedImg > (imgCache.length-1)) selectedImg=0;
setTimeout(RotatingPicturesLoop, RotatingPicturesLoopTime);
}


// utility function revString found here:
// http://www.java2s.com/Code/JavaScript/Language-Basics/PlayingwithStrings.htm
function revString(str) {
var retStr = "";
for (i=str.length - 1 ; i > - 1 ; i--){
retStr += str.substr(i,1);
}
return retStr;
}


// add our function to the SharePoint OnLoad event
_spBodyOnLoadFunctionNames.push("RotatingPictures");

</script>

<!-- add your own formatting here... -->
<center>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td id="VU" height="125" width="160" align="center" valign="middle">
<a name="RotatingImageLnk" id="RotatingImageLnk" alt="click for larger picture">
<img src="/_layouts/images/dot.gif" name="RotatingImage" id="RotatingImage" border=0>
</a>
<span name="RotatingImageMsg" id="RotatingImageMsg"></span>
</td>
</tr>
</table>
</center>



 



 


 



 



.

SharePoint: Adding popups to Link lists (open in new window)

The links list web part is a quick and easy to add a list of links to vendors, other SharePoint sites or the most popular documents in a library. The problem is that the links list web part does not have an “Open in new window” option. So when your users click the list, they navigate away from your site.

A typical links list:

            image

To change a links list to force “Open in new window”:

  • Add a Content Editor Web Part (CEWP) just below the links list web part
  • Modify the CEWP and set a title then click Source Editor
  • Copy and paste the HTML and JavaScript below
  • Edit the JavaScript to change the word “Links” to the name of your links list web part (title of the web part, not the title of the actual list, although they may be the same)
    if (x(i).summary=="Links")     to
    if (x(i).summary=="Your Links List Title")
    (If you are not sure, display your page, select Source from the View menu and search for “summary”)
  • Also… in the Advanced section of the CEWP’s properties change Chrome to “None” to hide the CEWP
  • Exit the edit mode and see if it works

 

<script>
// CEWP trick from techtrainingnotes.blogspot.com!
// Find the link list  (change "Links" to your web part's name)
var x = document.getElementsByTagName("TABLE") // find all of the Tables 
  var LinkList
  var i=0;
  for (i=0;i<x.length;i++) 
  {
    if (x[i].summary=="Links")
    {
      //
      LinkList = x[i];
      break;
     } 
  }

// add a target to the <A> tags
var links = LinkList.getElementsByTagName("A") // find all of the 
  for (i=0;i<links.length;i++) 
  {
    links[i].target="_blank"
  }
</script>

 

 

.

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.