10/17/2012

Cincinnati PowerShell Events

 

Cincinnati PowerShell User Group

The next meeting of the Cincinnati PowerShell User Group is Thursday October 18th at MAX Technical Training. I'll be speaking on "How to use PowerShell to use, filter and merge data from multiple systems". I'll be showing how to work across three systems, AD, SharePoint and SQL to collect data about a subset of employees and post the results to a SharePoint list.

Go here to resister (not required to attend) http://www.meetup.com/TechLife-Cincinnati/events/84008152/

 

SharePoint Saturday Cincinnati

It's a SharePoint event, but there will be PowerShell content there! At least four sessions include PowerShell.

Go here for info and to register: http://www.sharepointsaturday.org/cincinnati
October 27th, 2010

.

10/14/2012

SharePoint - Filtering a View by Group Membership

 

I use this blog to both share things I have discovered about SharePoint and as a place to store "stuff" so I can find it later. Kind of like personal notes…  The following is not an original discovery, just a step by step set of notes for a solution from tips I have found elsewhere. The core XML that led to this article where found here:
http://spboom.com/sharepoint-development/how-to-filter-sharepoint-list-by-membership-in-sharepoint-group/
and here:
http://sympmarc.com/2010/06/16/caml-filter-for-current-group-membership/

Filtering a View by Group Membership

There are a number of possible solutions to this problem:

 

Filtering a View by Group Membership

Notes:

  • This is not security! Other views of the list will still display all of the items.
  • The XML query can be much, much more complicated with the addition of ANDs and ORs. For example, you might add an OR section to always show all items for site owners.
  • The following works on a view (XsltListViewWebPart), but will also work with a Data View (DataFormWebPart). For the DataFormWebPart you will have a little more work to do as the WHERE is embedded in the "selectcommand" string and all of the brackets are "escaped". Example:
    image
    You will need to write the WHERE as a single line of text and replace each "<" with "&lt;" and each ">" with "&gt;".

The following is for SharePoint 2010 and Office 365 (2010)…

  1. If you don't have a convenient group for testing, go create a SharePoint group with a few people who can help you test this.
  2. In your list add a new column:
    Name: "VisibleToGroup"  (any name will do as long as you know how to deal with spaces and special characters in the name)
  3. Add a few items to the list with a few "VisibleToGroup" blank, a few with your test group and one or two for say Site Owners or Members.
  4. Create a view for a list:
    1. Give it a name (maybe "Filtered by Group Membership")
    2. Add a Filter. Anything will do. This is just to add the <Where> section to the web part's XML.  Example: Created By equals [Me]
    3. Configure the rest of the view as usual and save it
  5. Open your site in SharePoint Designer 2010
  6. In the Site Object pane click Lists and Libraries
  7. Click your list and then click the view you just created
  8. In the Code pane search for <Where>
  9. Delete everything between <Where> and </Where>  (but leave these tags)
  10. Add the following bolded code inside of the Where tags:
      <Where>
        <Membership Type="CurrentUserGroups">
          <FieldRef Name="VisibleToGroup"/>
        </Membership>
      </Where>

    The above for a DataFormWebPart (Data View):
    &lt;Where&gt;&lt;Membership Type="CurrentUserGroups"&gt;&lt;FieldRef Name="VisibleToGroup"/&gt;&lt;/Membership&gt;&lt;/Where&gt;
  11. Change "VisibleToGroup" to your column name (remember if you used spaces in the name then see: how to deal with spaces and special characters in the name)
  12. Save the view and go test in the browser

 

The results…

Here's a view showing all tasks in a list, including the People Picker column for a selected group displayed:

  image

Here's the filtered view for a user who is in the Training Members and Training Friends groups:

  image

Here's the filtered view for a user who is in the Training Friends and Training Members groups:

  image

The first user only saw tasks 2 and 4. The second user saw only tasks 2 and 3. Neither user saw task 1 as it was not assigned to any group.

 

Got a better solution?

Post a comment to this article and share it!

.

10/10/2012

SharePoint–Finding Column Display and Internal Names

 

Many customizer and developer projects require knowing the "internal names" for list and library fields. For example the task list field "% Complete" is internally named "PercentComplete".

Here are a few ways to find the internal name:

  • From the browser
  • From SharePoint Designer
  • Using PowerShell
  • Using a C# Console Application
  • Using the Client Side Object Model
  • Using JavaScript Client Side Object Model and a Content Editor Web Part

    Pretty much something for everyone!

 

From the browser

Permissions needed: Must have Site Owner (Full Control) or Design permissions

This could be a bit tedious if you wanted to check all of the fields, but for just one it's quick.

  1. Display the list or library and click the List or Library Ribbon
  2. Click List or Library Settings
  3. Scroll down to the list of columns and click the column name
  4. Note the URL for the page… the internal name is listed at the end: 
        http://………&Field=Author

 

From SharePoint Designer

Permissions needed: Must have Site Owner (Full Control) or Design permissions (may only need edit permissions in the library holding the web part page… To Do for Mike: need to test this!)

  1. In SharePoint Designer 2010 open your site and edit a web part page
  2. Click in a web part zone, click the Insert ribbon tab, click Data View and Empty Data View
  3. Click "Click here to select a data source" and pick your list
  4. In the Data Source Details pane mouse over the sample data (or the blank area below the field name) and the XSLT path the field will be displayed. The value after the "@" is the internal name.
    image

 

Using PowerShell

Permissions needed: Administrator access to the server and permissions to the site (PowerShell is an administrator's tool)

$web = Get-SPWeb http://sharepoint/sites/training/salestraining
$list = $web.Lists["Announcements"]
$list.fields | select Title, InternalName, Hidden, CanBeDeleted | sort title | ft -AutoSize

As you will most often be interested in the non-hidden fields, you can add a Where to filter them:

$list.fields | select Title, InternalName, Hidden, Sealed, CanBeDeleted | where {$_.Hidden -eq $false} | sort title | ft –AutoSize
 

Using a C# Console Application

Permissions needed: Administrator access to the server and permissions to the site (the code must run on the server)

using System;
using Microsoft.SharePoint;  // add a reference to Microsoft.SharePoint

// remember to change the Build Platform Target to x64!
namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            SPSite site = new SPSite("http://sharepoint/sites/Training/");
            SPWeb web = site.AllWebs["salestraining"];
            SPList list = web.Lists["Announcements"];

            Console.WriteLine("Title - Internal Name - Hidden - CanBeDeleted");
            foreach (SPField f in list.Fields)
            {
                Console.WriteLine("{0} - {1} - {2} - {3}", f.Title, f.InternalName, f.Hidden, f.CanBeDeleted);
            }
            site.Dispose();
            Console.ReadLine();
        }
    }
}

 

Using the Client Side Object Model

Permissions needed: May only need view permissions in the library holding the web part page… (To Do for Mike: need to test this!)

You can write and run Client Side Object Model (CSOM) code from your local PC and not need access to the SharePoint Servers. The following is a little console application with references added for Microsoft.SharePoint.Client and Microsoft.SharePoint.Client.Runtime.

using System;

using Microsoft.SharePoint.Client;

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            string url = "http://sharepoint/sites/training";
            ClientContext context = new ClientContext(url);
            Web web = context.Web;
            var list = web.Lists.GetByTitle("Announcements");

            context.Load(list.Fields);
            context.ExecuteQuery();

            Console.WriteLine(list.Fields.Count);
            foreach (Field f in list.Fields)
            {
                Console.WriteLine("{0} - {1} - {2} - {3}", f.Title, f.InternalName, f.Hidden, f.CanBeDeleted);
            }
            Console.ReadLine();
        }
    }
}

 

Using JavaScript Client Side Object Model and a Content Editor Web Part

Permissions needed: May only need view permissions to view the page… (To Do for Mike: need to test this!)

image

Steps:

  1. Open Notepad and copy and paste the code below
  2. Save the file as GetFieldName.htm
  3. Upload the file to a library (SiteAssets, Shared Documents, etc.)
  4. Right-click the uploaded file and copy the shortcut (the URL)
  5. Go to a web part page or the home page and add a Content Editor Web Part
  6. Edit the web part and set the Content Link to the URL of the file you just uploaded
  7. Save your changes and test!

                  image

<input type="text" id="ListName" value="Tasks"></input>
<button onclick='GetFieldList()'>Get Field List</button>

<script type="text/javascript">

function GetFieldList()
{
  var listname = document.getElementById("ListName").value;
  var ctx = SP.ClientContext.get_current();
  this.web = ctx.get_web();
  ctx.load(this.web);
  this.list = web.get_lists().getByTitle(listname);
  ctx.load(this.list);
  this.fields = this.list.get_fields();
  ctx.load(this.fields); 

  ctx.executeQueryAsync(Function.createDelegate(this, this.getListInfoSuccess), Function.createDelegate(this, this.getListInfoFail));
}

function getListInfoSuccess(sender, args) 
{
        var fieldEnumerator = this.fields.getEnumerator(); 
        var results="";
        while (fieldEnumerator.moveNext()) { 
            var oField = fieldEnumerator.get_current(); 
            if (!oField.get_hidden())
            results+= oField.get_title()
                + " - " + oField.get_internalName()
                + " - " + oField.get_hidden()
                + "\n";
        }
        alert(results);
}    
function getListInfoFail(sender, args) 
{
 alert('Something failed. Error:'+args.get_message());    
}

</script>

10/08/2012

End of support for Internet Explorer 7 in Office 365

 

Just got the latest service alert for Office 365…

End of support for Internet Explorer 7
Internet Explorer 7 is not compatible with the updates to Office Web Apps. For the best user experience, Office 365 users should continue to use a modern web browser.

Safari 4.x is also no longer supported. (But newer versions are.)

More here: http://community.office365.com/en-us/wikis/office_365_service_updates/update-to-office-web-apps-with-sharepoint-su4.aspx

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.