SharePoint Dragons

Nikander & Margriet on SharePoint

Emulating browsers and weird CSS problem

Recently, we experienced a weird problem in MSIE 9 where select boxes kept closing themselves when hovering over them, in later browsers we didn’t experience this issue. It turned out that this was caused by multiple CSS selectors pertaining to font families defined in different CSS files which were targeting the same select box. Both CSS files did something like:

select {font-family:’Avenir LT W01 85 Heavy';}

Removing one of them solved the issue, and allegedly this should do the trick too:

select option {font-family:’Avenir LT W01 85 Heavy';}

This is described in more detail at: http://stackoverflow.com/questions/5551288/ies-select-boxes-closes-themselves-when-hovering

In the process, we found that MSIE 11 Enterprise Mode causes the browser to run in IE 8 compatibility mode, but this didn’t cause the self-closing select box problem, so this compatibility mode doesn’t seem to be full-fidelity. This can be turned on or off by opening MSIE 11, press ALT > Tools > Enterprise Mode (or: ALT > Extra > Ondernemingsmodus in Dutch). Read more about MSIE 11 Enterprise mode over at: http://www.zdnet.com/article/internet-explorer-11-to-get-new-enterprise-mode/

It also turned out that the problem didn’t appear in MSIE 11 compatibility mode (press F12, next to the Search box choose a compatibility mode such as 8, 9, or 10). As it turned out we were able to use IETester (http://www.my-debugbar.com/wiki/IETester/HomePage) and it was able to simulate MSIE 9 in such a way that we could reproduce the self-closing CSS issue.

Note to Self: Don’t forget to add to indexed properties

If you want to add a property to the spweb property bag, you might want to consider to ad dit to the IndexedPropertyKeys collection as well. This causes the creation of a new crawled property the First time after a full crawl has taken place. The code looks something like this:

using (var site = new SPSite(“http://thesite_coll_url”))

            {

using (var web = site.OpenWeb())

                {

string propKey = “lctest”;

string propValue = “lcvalue”;

                    web.AllProperties[propKey] = propValue;

if (!web.IndexedPropertyKeys.Contains(propKey))

                    {

                        web.IndexedPropertyKeys.Add(propKey);

                    }

                    web.Update();

                }

            }

SharePoint 2013 IIS Lockdown: Dangerous HTTP methods

Security assessments typically advise to lockdown IIS and limit the number of available HTTP methods that can be used to the minimum.

Tools such as Urlscan (http://learn.iis.net/page.aspx/473/using-urlscan) can help with that, but the big question is if it is a good idea to use such tools in a SharePoint environment.

For a typical web application, support for the HTTP GET and POST methods may be enough, but SharePoint is not aywhere near typical. Forstarters, it supports the WebDAV, REST, and FrontPage Server Extensions protocols.

The following URL contains a list of all known HTTP methods: http://msdn.microsoft.com/en-us/library/aa364664(v=vs.85).aspx

The next URL contains a list of all WebDAV methods: http://msdn.microsoft.com/en-us/library/aa142917(v=EXCHG.65).aspx

Problem is we didn’t find an exhaustive list containing all HTTP methods that are supported within SharePoint. But we did find that SharePoint supports the following HTTP methods (which are actually the majority of all available HTTP methods):

– COPY, DELETE, GET, GETLIB, HEAD, LOCK, MERGE, MKCOL, MOVE, OPTIONS, POST, PROPFIND, PROPPATCH, PUT, UNLOCK.

Further more, the section of the web.config files of sharepoint web applications indicate that most handlers support ALL HTTP methods. Therefore, we consider it to be too risky to exclude dangerous HTTP methods. The only thing that would change our mind would be an exhaustive list with all HTTP methods supported by SharePoint 2013, published by MS themselves.

Disable ASP.NET button after click

The combination of the properties OnClientClick and UseSubmitBehavior prevent a button from being clicked twice before completed.

The following makes sure the button can’t be clicked twice:

OnClientClick=”javascript:this.disabled=’disabled'”

But, this also means the ASP.NET click event won’t happen!!! In order to do so you need to set the following:

UseSubmitBehavior=”False”

Setting this property to true bypasses the client browser’s submit mechanism in favor of the ASP.NET postback mechanism. Setting this leads to the insertion of some client-side script to the page th post the form to the server. Here’s a complete example that can be included in an .aspx page:

My Tasks web part outside of MySites, but pointing to the personal site task list?

We had a requirement to place a My Tasks web part outside of SharePoint personal sites, in a regular site collection, pointing to the Tasks list of a personal site. There were two interesting blog posts surrounding this topic. The first one, http://bernado-nguyen-hoan.com/2013/03/03/making-my-tasks-web-part-available-outside-of-mysites/ , mentions that it’s possible to use the My Tasks web part outside of My Sites by enabling the hidden My Tasks Dashboards feature on a specific web, which can be done like this:

Enable-SPFeature 89D1184C-8191-4303-A430-7A24291531C9 -url [http://[url_web]http://[url_web]

Doing that actually adds the My Tasks web part to the web part gallery, but it is not enough. The next resource has more to say about that: http://yalla.itgroove.net/2014/04/27/use-sharepoint-tasks-web-part-outside-sites/ The approach proposed here involves exporting the My Tasks web part, then import it in the other site collection and copy a couple of pages needed by this web part to another site collection. The presence of these pages is an absolute necessity to get the My Tasks web part. After doing some experimenting, most of the tabs of the My Tasks web part indeed work correctly (namely “Active”, “Completed”, and “Recently Added”) after following this approach, but the “Important and Upcoming” tab remains a problem. That is, if you want it to refer to the Personal Site task list.

This problem, that lies in the TimeLine web part, is quite definitive. As it turns out, the web part calls a method named IsAddressValid() of the TimelineDataSourceToolPart web part (which is part of the Microsoft.SharePoint.WebPartPages namespace of the Microsoft.SharePoint assembly). This method checks that the data source points to a URL that is part of the same site collection hosting the My Tasks web part. So, site collection X can never have a working “Important and Upcoming” tab in a My Tasks web part that points to the Personal Site Tasks list.

Diff Checker

Nice web site that can check differences between texts: https://www.diffchecker.com/ in case you do have internet access but don’t have access to a more advanced comparison tool.

Imagine Cup

Check out Margriet’s latest TechNet Wiki blog post about the Imagine Cup: http://blogs.technet.com/b/wikininjas/archive/2014/12/25/the-imagine-cup.aspx

Are Draft versions of items and documents indexed in SharePoint 2013?

This can be tested for both lists and document libraries, and the answer depends on various list settings (a term we use in a generic way that also includes document library settings). Possible list settings are:
– Content approval setting: With or without content approval
– Draft item security: Any user who can read items, Only users who can approve items, or Any user who can approve items (and the author of the item).

Searching using the credentials of the author results in items in lists as well as document libraries that only require Read permissions (option “Any user who can read items”). All other Draft versions in lists and libraries with different settings are not included in search results. For instance, a document in Draft version in a library that has the following condition: [go to document library > Library > Library Settings > Versioning settings > Draft Item Security > Only users who can edit items] is NOT returned.

Searching under the context of a user that only has READ permissions yields the exact same search results.

Investigating the crawl log shows that the items that are not returned aren’t even indexed.

Microsoft Fakes: building a shim for the SharePoint 2013 SSOM

We were building a mail class used by SharePoint solutions that leverages the SmtpClient class because SPUtility.SendEmail() is too limited in some ways:

  1. It doesn’t send attachments.
  2. It contains a max of 2048 chars per line, although this can be circumvented by adding line breaks (‘\n’).

More about those limitations over here: http://sharepointdragons.com/2012/05/21/sputility-sendemail-limit/

However, we did want to use the SSOM to determine the SMTP server that should send the e-mail messages for us. We could do it like so:

System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient(objWeb.Site.WebApplication.OutboundMailServiceInstance.Server.Address);

But in this case, we went for this solution:

SPAdministrationWebApplication.Local.OutboundMailServiceInstance.Server.Address;

This resulted in the following method implementation in our custom SharePoint library is a class called Manager:

public string GetSmtpServer()
{
return Microsoft.SharePoint.Administration.SPAdministrationWebApplication.Local.OutboundMailServiceInstance.Server.Address;
}

Very simple. Then, we decided we needed to add some unit testing. If you have VS.NET Ultimate, you can consider using Microsoft.SharePoint.Emulators. We gave it a spin and weren’t that happy with it. At some point, we had to uninstall the package, switch the project to x86, install the emulator again, and switch back to x64, and more stuff like that. But apparently it can be done, according to: http://writeabout.net/2014/06/21/spemulators-available-on-nuget/ , so don’t let us stop you from checking it out!

Then, we were considering other Mocking frameworks (Typemock Isolator, JustMock, Microsoft Fakes) and decided to go with Fakes because of monetary reasons. We then added a unit test project ( VS.NET 2012 > Add > New Project > Unit Test Project), added a reference to our custom SharePoint libary, right-clicked it and chose Add Fakes Assembly.

If you want to know more about Fakes, check out http://msdn.microsoft.com/en-us/library/hh549176.aspx . Basically, it allows you to replace methods and properties during run time with your own implementation.

Because our custom SharePoint library uses the SPS 2013 SSOM it’s built for 64 bit, which required us to change the unit test project to 64 bit too (right-click unit test project > Properties > Build > Platform target: x64). That is not all, you also need to set the Test processor architecture to 64 bit, like so: VS.NET 2012 > TEST > Test Settings > Default Processor Architecture > X64.

When that is done, the unit test project is able to call the SharePoint custom library and we were able to create a shim for our GetSMTPServer() method., which goes something like this:

[TestMethod]
public void GetSmtpServerReturnsFakeName()
{
using (ShimsContext.Create())
{
MyLib.Fakes.ShimManager.AllInstances.GetSmtpServer = (@this) => { return ”mySMTPServer”; };
Manager man = new Manager();

// returns mySMTPServer
string smtpServer = man.GetSmtpServer();
}
}

Smartphone simulators

To test the mobile view functionality in SharePoint 2013, we needed some smartphone emulators. Here’s what we came up with…

This web-based iPhone simulator is quite nice: http://iphone4simulator.com/

For the iPhone, there’s also a commercial product which is easy to use and has a trial version. It can be found at http://www.electricplum.com/studio.aspx

For the Windows Phone, you need to download the SDK at http://dev.windows.com/en-us/develop/download-phone-sdk , which uses Visual Studio (2012) and the presence of Hyper-V. This emulator itself can’t run on a virtual machine (although we’ve seen posts that say VMWare 9 can do it).

For Android, check out http://developer.android.com/sdk/index.html

Follow

Get every new post delivered to your Inbox.

Join 462 other followers