Thursday, May 29, 2014

Set the column width i SharePoint

Just a small script for safe keeping. This script will search for column with a title e.g. Name and set the column width. To set more columns, add new line to the script and change the selector

1 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" type="text/javascript">
2 </script><script type="text/javascript">
3 $(function(){
4 $(".ms-viewheadertr th:contains('Name')").css("width", "50px");
5 });
6 </script>
7

This script is tested with document libraries both on 2010 and 2013.

Tuesday, May 27, 2014

SPBG user group meeting in Aarhus August 15.

There are arrange knowledge sharing meeting about Self-service BI capabilities of Office 365 and SharePoint dinner on Aug. 15 in Aarhus. Read more about the event here http://spbg.dk/Lists/Mder/DispForm.aspx?ID=70

Wednesday, May 21, 2014

Anonyms user download Excel file without prompt for password

Last week I had a problem, that I have met a few times before. The problem is when an user clicks on an Excel file and open the file. Then the user gets a login box. Although that anonymous access is enabled. I also tested to give anonyms users full control but no luck. The solution is to change the web.config for the web application and remove the "verse" options and plug locate the system.webServer /security/requestFiltering

The web.config before:

1 <system.webServer>
2 <security>
3 <requestFiltering allowDoubleEscaping="true">
4 <requestLimits maxAllowedContentLength="2147483647" />
5 </requestFiltering>
6 </security>

The web.config after:


1 <system.webServer>
2 <security>
3 <requestFiltering allowDoubleEscaping="true">
4 <requestLimits maxAllowedContentLength="2147483647" />
5 <verbs allowUnlisted="true">
6 <add verb="OPTIONS" allowed="false" />
7 <add verb="PROPFIND" allowed="false" />
8 </verbs>
9 </requestFiltering>
10 </security>

Wednesday, May 14, 2014

A little, more, REST

By using the SharePoint app, _api JSON Viewer, http://office.microsoft.com/en-us/store/api-json-viewer-WA103999972.aspx, we can easily execute and test REST request. When we start the _api JSON Viewer, we can enter a request in to the “query textbox” like query for all lists on host web.

1

Now we have the result for the lists

clip_image003

If we reenter the query for only retrieve the title of the list

clip_image005

and even add a more advanced query, by using the $filter query option.clip_image007

For more information about the REST request and query operations look here “Use OData query operations in SharePoint REST requests

Looking for more REST? Look here "A little rest"

Thursday, May 1, 2014

Office 365 and SSO/ADFS

I have a customer who had an old integration with Office 365, which sync list items. The customer is now switched over to SSO/ADFS and the old code began to fail. The old code was built around building a cookie through MsOnlineClaimsHelper class:

1 string sharepointUrl = "https://<SharePointUrl>.sharepoint.com";
2 string username = "<username>@<domain>";
3 string password = "<passoword>";
4
5 using (Microsoft.SharePoint.Client.ClientContext clientContext = new Microsoft.SharePoint.Client.ClientContext(sharepointUrl))
6 {
7 MsOnlineClaimsHelper helper = new MsOnlineClaimsHelper(username, password, sharepointUrl);
8 clientContext.ExecutingWebRequest += helper.clientContext_ExecutingWebRequest;
9 Microsoft.SharePoint.Client.Web web = clientContext.Web;
10 clientContext.Load(web, w => w.Title);
11 clientContext.ExecuteQuery();
12 Console.WriteLine(web.Title);
13 }

When the code runs gives the error:
"An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail."
error 
But instead of using MsOnlineClaimsHelper, then there is a new SharePointOnlineCredentials class in SharePoint.Client CSOM api that will fix this error.



1 string sharepointUrl = "https://<SharePointUrl>.sharepoint.com";
2 string username = "<username>@<domain>";
3 string password = "<passoword>";
4
5 SecureString passWordString = new SecureString();
6 foreach (char c in password.ToCharArray()) passWordString.AppendChar(c);
7
8 Microsoft.SharePoint.Client.SharePointOnlineCredentials credentials = new Microsoft.SharePoint.Client.SharePointOnlineCredentials(username, passWordString);
9
10 using (Microsoft.SharePoint.Client.ClientContext clientContext = new Microsoft.SharePoint.Client.ClientContext(sharepointUrl))
11 {
12 clientContext.Credentials = credentials;
13
14 Microsoft.SharePoint.Client.Web web = clientContext.Web;
15 clientContext.Load(web, w => w.Title);
16 clientContext.ExecuteQuery();
17 Console.WriteLine(web.Title);
18 }

If you need the auth cookie for like a webservice call or a REST call you can get the cookie like this


1 ListService.Lists listService = new ListService.Lists();
2 Uri sharepointuri = new Uri(sharepointUrl);
3 string authCookie = credentials.GetAuthenticationCookie(sharepointuri);
4 listService.CookieContainer = new System.Net.CookieContainer();
5 listService.CookieContainer.Add(new System.Net.Cookie("FedAuth", authCookie.Replace("SPOIDCRL=", string.Empty), string.Empty, sharepointuri.Authority));
6 listService.UseDefaultCredentials = false;