Friday, March 1, 2013 #

Open SharePoint Alerts Page Using JavaScript

The page to set up alerts for a SharePoint list requires the list ID to be passed in as a query string. The follow code will get the ID for the list with a specific title. It will  then open the alerts setup page for that list in a SharePoint dialog box.

   1:  var context = new SP.ClientContext.get_current();
   2:  var listTitle = 'TitleOfYourList';
   3:  var list = context.get_web().get_lists().getByTitle(listTitle); 
   4:  context.load(list);
   5:   
   6:  context.executeQueryAsync(function (sender, args) {
   7:      var id = list.get_id();
   8:      NewItem2(e, 'http://yoursite/_layouts/SubNew.aspx?List=' +id);
   9:  });

Posted On Friday, March 1, 2013 2:04 PM | Comments (0)

Wednesday, November 14, 2012 #

Credentials Not Passed From SharePoint WebPart to WCF Service

I have spent several hours trying to resolve this problem, so I wanted to share my findings in case someone else might have the same problem.

I had a web part which was calling out to a WCF service on another server to get some data. The code I had was essentially

using System.ServiceModel;
using System.ServiceModel.Channels;
...
var binding = new CustomBinding( new HttpTransportBindingElement { AuthenticationScheme = System.Net.AuthenticationSchemes.Negotiate } );
var endpoint = new EndpointAddress(new Uri("http://someotherserver/someotherservice.svc"));
var someOtherService = new SomeOtherServiceClient(binding, endpoint);
string result = someOtherService.SomeServiceMethod(); 

This code would run fine on my local instance of SharePoint 2010 (Windows 7 64-bit). However, when I would deploy it to the testing environment, I would get a yellow screen of death  with the following message:

The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'Negotiate,NTLM'.

ysod

I then went through the usual checklist of Windows Authentication problems:

  • Check WCF bindings to make sure authentication is set correctly
  • Check IIS to make sure Windows Authentication is enabled and anonymous authentication was disabled.
  • Check to make sure the SharePoint server trusted the server hosting the WCF service
  • Verify that the account that the IIS application pool is running under has access to the other server

I then spend lot of time digging into really obscure IIS, machine.config, and trust settings (as well of lots of time on Google and StackOverflow). Eventually I stumbled upon a blog post by Todd Bleeker describing how to run code under the application pool identity.

Wait, what? The code is not already running under application pool identity?

Another quick Google search led me to an MSDN page that imply that SharePoint indeed does not run under the app pool credentials by default. Instead SPSecurity.RunWithElevatedPrivileges is needed to run code under the app pool identity. Therefore, changing my code to the following worked seamlessly

using System.ServiceModel;
using System.ServiceModel.Channels;
using Microsoft.SharePoint;
...
var binding = new CustomBinding( new HttpTransportBindingElement { AuthenticationScheme = System.Net.AuthenticationSchemes.Negotiate } );
var endpoint = new EndpointAddress(new Uri("http://someotherserver/someotherservice.svc"));
var someOtherService = new SomeOtherServiceClient(binding, endpoint);
string result;
SPSecurity.RunWithElevatedPrivileges(()=> 
{
    result = someOtherService.SomeServiceMethod(); 
});

Posted On Wednesday, November 14, 2012 9:56 AM | Comments (1)

Thursday, December 1, 2011 #

WPF Asynchronous Wait Cursor using Task Parralel Library

While working on a WPF application, I had a need to show the wait cursor while performing a long running operation. However, I didn't want the long running process tying up the UI thread. I needed to run the long running operation on its own thread. I decided to use the Task Parallel Library (TPL) to help.

Posted On Thursday, December 1, 2011 1:17 PM | Comments (3)

Tuesday, May 3, 2011 #

Use HMTL and JavaScript to Display Presence Controls in SharePoint 2007

When you have Microsoft Office Communicator or Lync installed, and you visit a SharePoint site, you will get these presence indicators next to peoples’ names...In SharePoint 2007 (or any other web page), whenever I needed to display a presence icon in custom code, I just use the following HMTL/CSS/JavaScript

Posted On Tuesday, May 3, 2011 12:57 PM | Comments (33)