Using a CURRENT USER FILTER on a list

Simple instruction on adding a 'current user filter' to filter a list web part on a sharepoint 2010 page.
For these instructions we will assume you have:
First we need to slightly modify the list.
Click on the link to your list in the quick launch bar on the left hand side or navigate to your sites lists and select it from there.
navigate to list sharepoint 2010
 Click on the list settings button on the list tools>list ribbon.
list settings sharepoint 2010
Click on the 'person' type column that you wish to filter by current user, then under the 'additional column settings' options ensure that the 'Show field' dropdown is set to 'account'.
show field share point 2010
 Navigate back to your page that has the list added as a web page and click the edit page icon. Then on the editing tools > Insert ribbon click the web part button.
web part insert sharepoint 2010
 From the options that appear select the Current User Filter from the filters folder and click add. Then click the save page button to save where we are up to.
current user filter
This is where it can get a bit tricky. The Current user web part does not appear immediately on the screen nor does it have any immediate affect until we configure it.
In order to configure the web part from here seems a bit poorly thought out but here is how I go about it.
Click the edit page button then hover over your list web part and click the edit web part select from the arrow dropdown at the very right hand site of the list web part.
list web part edit
 This will now make the current user filter appear on the page.
Now from the dropdown on the Current user filter web part select Connections > Send filter values to > #your list name#.
web part connections
 In the dialog that pops up ensure that 'Get filter values from' is selected in the dropdown and press configure.
 configure connections
If a "Confirm dialog preference" pops up press cancel. Then in the next popup ensure your 'person' type field that we modified earlier is selected then press Finish. Save the page.
configure web part connection
 You should be left with a list that only has items filtered to the current user....
filter current user

Enable Anonymous Access in SharePoint 2010

It is not much different then SharePoint 2007 set up, the only difference is the GUI or the Ribbon.
1. Starting in Central Administration, under Application Management, click on the Manage web applications.
Anonymous Access Set Up Step 1
2. Make sure you select the site you want to enable anonymous access and click on the Authentication Providers icon.
Anonymous Access Set Up Step 2
3. On the Authentication Providers pop-up window click on the Default zone.
Anonymous Access Set Up Step 3
4. Under Edit Authentication, check Enable anonymous access and click Save.
Anonymous Access Set Up Step 4
5. Going back to Web Application Management click on the Anonymous Policy icon.
Anonymous Access Set Up Step 5
6. Under Anonymous Access Restrictions select your Zone and set the Permissions to None – No policy and click Save.
Anonymous Access Set Up Step 6
7. Now, web application will allow anonymous access to be set. So, navigate to your top level site collection for the web application. Click the Site Actions > Site Settings. Under Users and Permissions click Site permissions.
Anonymous Access Set Up Step 7
8. Under Permission Tools, click Anonymous Access icon and set the permissions to Entire Web site and click OK.
Anonymous Access Set Up Step 8
Anonymous Access Set Up Step 8
Anonymous Access Set Up
That’s all, folks! If you followed these steps properly you should have now Anonymous Access enabled.

Customize the ribbon programmatically from web parts and field controls

  1. Customizing the ribbon – creating tabs, groups and controls
  2. Adding ribbon items into existing tabs/groups
  3. Ribbon customizations – dropdown controls, Client Object Model and JavaScript Page Components
  4. Customize the ribbon programmatically from web parts and field controls
In contrast to my earlier posts, this article isn’t a detailed walkthrough – rather, it is a compendium of techniques and information which should help you implement ribbon customizations for web parts, custom field controls or indeed, any other kind of page control. At the time of writing I haven’t really seen a great deal written on this, aside from a couple of resources I’ll mention. I would have loved to have written detailed walkthroughs here, but alas I can’t because a) Microsoft have recently published some good info for one of the scenarios, so I’d prefer to point you to that, b) To run through all the scenarios here in depth would take weeks and c) Because if I don’t stop writing about the ribbon soon I’ll still be on this topic this time next year, and frankly I have a  book chapter to write on a completely different area of SharePoint 2010 which I need to crack on with! So we’ll look at each requirement and I’ll discuss what I think are the key techniques you’d use along with some observations from me.
Note that due to the general lack of documentation so far on this topic (and the fact I haven’t bottomed everything out in all the scenarios), a couple of things here are speculation rather than hard fact. I’ll make these items clear, and will endeavour to come back to this article and add updates as new information emerges. 
Before we dive in, remember that if you’re abiding by ribbon design principles you should most likely be working with a ContextualGroup (discussed towards the end of Adding ribbon items into existing tabs/groups) – this is the container to use for ribbon elements which are only relevant depending on what the user is doing (shown visible but not active here):
ContextualGroup
If this isn’t what you want, note that things are probably easier if you just need to add some controls on an existing tab or group which get activated under certain circumstances. In this case you can just supply some JavaScript to the ‘EnabledScript’ attribute of your controls – I showed this in my Notifications/Status demo in Customizing the ribbon (part 1) – creating tabs, groups and controls. The rest of this article focuses on how you might get a contextual group (see image above) to show in different scenarios.
 Adding ribbon items from a web part
In SharePoint 2010 the web part framework now has special provision for ribbon customizations, which means a couple of things are taken care of for you. Microsoft have now published some guidance on this scenario in the form of an article on the SharePoint Developer Documentation blog – How to Create a Web Part with a Contextual Tab. There’s a lot of golden info in there, but I’ll distil the main points here:
  • Using server-side code, the ‘RegisterDataExtension’ method of SPRibbon can be used to pass XML to the ribbon framework.
    • This is an alternative to the fully declarative approach using the CustomAction element. As far as I can tell, either technique can be used for ribbon customizations specific to a certain control only (as opposed to ribbon customizations for say, all lists of a specific type where CustomAction is the way to go).
  • Your web part needs to implement the newIWebPartPageComponentProvider interface and it’sWebPartContextualInfo property
    • This allows you to specify information about the associated ribbon customization(s) and the ID of the associated page component (which we discussed last time) for your custom bits.This allows the ribbon framework to ‘link’ your web part with your ribbon changes – meaning that certain things are taken care of for you e.g. firing commands only when your web part has focus on the page (if you specified this behaviour by use of ‘getFocusedCommands’ in your page component). Without this you would have to write JavaScript code to manually handle page events for controls emitted by your web part e.g. the click event for a textbox.
Adding ribbon items from a field control
Like web parts, I think (speculating here) there is special provision in the framework for ribbon customizations from a field control. Consider that, like web parts, field controls should typically only show their contextual ribbon options when they have focus – since this would be the case for all field controls, it makes sense to me that Microsoft might abstract some handling around this for us. If not, you would be responsible for writing JavaScript to detect when the user clicked into your field so that you could show your ContextualGroup.
Digging around, I notice that all SharePoint field controls have 4 new properties (since they are implemented on one of the base classes,Microsoft.SharePoint.WebControls.FormComponent):
  • RibbonTabCommand
  • RibbonContextualGroupCommand
  • RibbonGroupCommand
  • RibbonCommand
I’m surmising that these control properties would be set declaratively in the hosting page and are designed to match up with commands specified in an accompanying page component – this would enable you to run client-side code similar to my sample last time, perhaps to initialize data for your ribbon controls and so on. However, when I try to implement these commands, my page component’s ‘handleCommand’ method never receives these commands. So either I’m doing something wrong or this theory is incorrect. In which case, not to worry ribbon customizations for field controls should still be entirely possible, there will just be more work to do. Read on.
Using server-side code to show ribbon items
Thinking outside of any ‘framework support’ for where our ribbon customizations are targeted at, we can always write server-side or client-side code to show a contextual group. In fact, I already showed the server-side code for this in Adding ribbon items into existing tabs/groups (ribbon customization part 2):
protected override void OnPreRender(EventArgs e)

{

    SPRibbon currentRibbon = SPRibbon.GetCurrent(this.Page);

    currentRibbon.MakeTabAvailable("COB.SharePoint.Ribbon.ContextualTab");

    currentRibbon.MakeContextualGroupInitiallyVisible("COB.SharePoint.Ribbon.ContextualGroup", string.Empty);

    

    base.OnPreRender(e);

}
This is probably only appropriate if your stuff is contextual-ish – an application page would be a good example of this. In this example all we care about is that the user is on our page, then we can show our options. It doesn’t matter which control has focus, effectively our options are OK to show by default when the page loads. However, if you need page-level ‘contextuality’ (I may have just invented that word by the way – use it in a sentence to your boss today) then most likely you’ll be wanting to use JavaScript to show your contextual group when the user is doing something specific on the page e.g. editing a certain field. You’d then be looking to some client-side code to detect this and respond accordingly.  
Using client-side code to show ribbon items
So, final scenario – what if you need to show ribbon items from something which isn’t a web part or field control (or like me you couldn’t get there with anything in the field control framework which may or may not be designed to help), and it has to be done client-side to be fully contextual? Well, disappointingly I’m drawing another blank here so far – I’d love to hear from anyone who knows the answer to this. In case you’re doing ribbon development and are interested, here’s a summary of my journey:
  • Checked SP.Ribbon namespace in Client OM
  • Spent many happy hours in the debugger and various out-of-the-box JavaScript files, looking for examples of where the core product does this (e.g. calendar, rich text editor to name a couple)
  • Found some interesting methods on the CUI.Ribbon object, such as showContextualGroup(‘foo’) and selectTabByCommand(‘bar’)
    • Noted that across the entire SharePoint root, these methods are only called by the RTE, not globally across the SharePoint codebase
    • Noted that the RTE code gets a CUI.Ribbon instance from a property (RTE.RichTextEditorComponent.$3b() – N.B. most of the JS is obfuscated or machine-generated* down here)
  • Tried to use SP.Ribbon.PageManager.get_instance().get_ribbon() (used elsewhere in the OOTB codebase) to get me a CUI.Ribbon instance, however this gave me a null
  • Tried to use the ‘_ribbon’ page level variable, however this appears not to be of type CUI.Ribbon as the debugger shows it does not have the methods I’m trying to call
  • Tried a couple of other things which I’ve forgotten now
Needless to say, I’d love to hear what I’m missing on this. If nothing else, hopefully MS will release some more information soon which will shed some light on how to handle this scenario.
Summary
This post doesn’t claim to have all the answers, but it might serve as a “leg up” if you’re trying to build any of these scenarios now. I’m hoping that the lack of deep information in this area is a reflection on the fact that RTM is still some time away, and that ribbon dev will get some love in the SDK between now and then. The key scenarios I discussed here are displaying custom ribbon elements from web parts and field controls, but also the more generic cases of displaying customizations with server or client-side code.

SharePoint 2010: Get Full or Relative Url of web using EcmaScript

Sometimes from client side, you need to know the current web url. And for this little information you don’t want to call EcmaScript’s load function to get information from server side. Actually the information can be found without any server call. You can access the information from ClientContext as shown below.
var context = new SP.ClientContext();
var relativeWebUrl = context.get_url();
Remember the get_url method will only return relative url of the site. As shown in the following table:
Site Collection UrlSite Urlcontext.get_url() response
http://mysite.comhttp://mysite.com/
http://mysite.comhttp://mysite.com/site1/site1
http://mysite.com/siteshttp://mysite.com/sites/site1/sites/site
So if you need to know the full url of the site you can do so easily with the following script:
function getFullWebUrl() {
    var context = new SP.ClientContext();
    var relativeWebUrl = context.get_url();
    var fullWebUrl = window.location.protocol + '//' + window.location.host + relativeWebUrl ;
    alert(fullWebUrl);
}