Using PowerShell to set ULS logging level to “extra verbose” to catch all the events in the logs

Stock photo from pixabay.com

This blog post describes how set the SharePoint’s ULS level to “Extra Verbose” (VerboseEx) using PowerShell. This is not possible using the browser UI.

Description of the solution

By default, ULS logging is somewhat non-detailed, and a lot of data that could be used to debug issues is omitted. The UI cannot be used to set this level of logging – it is limited to verbose. In case you really, REALLY need to get all the data logged to ULS, you can use PowerShell to enable verboseex -level tracing, using the following command:

Beware, though: this will generate a lot of data, and it’s likely you won’t be able to do anything with the log files using notepad++ or similar tool, as a single file can be hundreds of megabytes, and handling that might get a little tricky.

You can always reset this setting to default (medium-level tracing) by running the following command:

 

More info about the trace levels:

Disabling anonymous access on a single site through PowerShell

Anonymous access in SharePoint 2013

This post is about managing Anonymous Access on a SharePoint site (SPWeb) using PowerShell commandlets. It’s often a lot more feasible and even easier than using the browser interface!

Description

Assume you have a site collection that’s published to the whole world. You’ll have anonymous access enabled at both web application and site collection -levels, and configured permissions at the root web -level. Now, let’s assume you want to disable anonymous access on a certain site deeper in the site structure. This way anonymous users could access your site at http://site.com and http://site.com/subsite, but not at http://site.com/subsite/deepsubsite. As an added bonus, that web would even be removed from the navigation for anonymous users (security trimming).

Solution(s)

Of course, you could do this through site permissions -page via browser (http://site.com/_layouts/15/user.aspx) by breaking permissions inheritance and disabling anonymous access, but there are multiple situations when this is not feasible – say, for example, that you already have a redirection for that certain url set in the IIS or gateway, and can’t access the page. Luckily, this can also be done with PowerShell.

 

This is a lot faster than through browser, right? 🙂 Just remember to use the right url for the web, SharePoint will find out the right zone for you!

Powershell Error: Cannot uninstall the LanguagePack 0 because it is not deployed.

Powershell: languagepack 0

Thi s post offers a solution to the very non-descriptive SharePoint error message “Cannot uninstall the LanguagePack 0 because it is not deployed”, which might appear while trying to update a wsp solution.

Symptoms

Assume you’re trying to install, update or uninstall a SharePoint solution (.wsp package) using PowerShell-commands Install-SPSolution, Update-SPSolution or Uninstall-SPSolution (respectively). Operation fails with the following (or similar) error:

I have actually seen this also in the form of “Cannot uninstall Language Pack 0 because it is not deployed”, but I think the other form of the error is the one that pops up in the PowerShell.

Powershell: languagepack 0

In Central Admin the solution is in Error state.

151117_ca

Solution

You can find quite a lot of solutions online, but they weren’t really working for me. I tried restarting services, removing the package and meddling with the dll-files, but to no avail. However, the actual “last operation details” on the CA page hinted that the problem was in fact in one of the features. The feature in question included some content types, and toying around with them is like playing baseball with hand grenades, so you have to tread carefully in cases like these.

Continue reading

Malformed web.config killing your ASP.NET-application or SharePoint (“Server Error in ‘/’ Application” or “Parser Error”)

Malformed web.config

Symptoms

Once you navigate to your site, you only get en error like this:

Server Error in ‘/’ Application.

Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Index was outside the bounds of the array.

The next few rows (source of the error) seem to vary wildly, but they’re something like this:

Parser Error

Line 3: <WebControls:XmlUrlDataSource runat=”server” AuthType=”None” HttpMethod=”GET”>
Line 4: <DataFileParameters>
Line 5: <WebPartPages:DataFormParameter Name=”RequestUrl” ParameterKey=”RequestUrl” PropertyName=”ParameterValues”/>
Line 6: </DataFileParameters>
Line 7: </WebControls:XmlUrlDataSource>

Continue reading

Visual Studio 2010 fails to show the design view of an aspx-page

SharePoint project properties

This post is about solving the issue with Visual Studio 2010 failing to show the design view of an .aspx-page. Luckily, it’s an easy and pretty classical fix.

Symptoms

While trying to view or edit an aspx-page in design mode in Visual Studio 2010, the window is just plain empty and there’s little you can do about it – selecting view markup or hitting F7 may not do anything and restarting the Visual Studio doesn’t help.

empty aspx page design view

Design view failing to open

Solution

The Design view requires connection to the SharePoint site where you’ll be deploying the solution (or rather, any site). Set the Site URL property in the project settings:

Continue reading

Quickest way to download all the wsp-packages in a SharePoint farm

PowerShell logo

Downloading all deployed farm solutions (wsp-packages) from a SharePoint farm is pretty simple using PowerShell. No need to download individual packages through cumbersome interfaces!

Solution

Got this one from the cool guys at C-Sharp Corner.

The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

Too long deployment path

This post describes a few different ways of fixing the error “The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.” one can get when trying to package/publish a SharePoint solution, web site or Azure Webjob.

UPDATE 11.4.2016: I actually got this nasty exception on another occasion (Azure webjob publish), so I updated the text accordingly.

Symptoms

Visual Studio throws the following error when packaging a SharePoint solution to a .wsp file, OR when deploying or publishing your web project (for example Azure Webjob).

 

Continue reading

Identifying IE11 compatibility mode in SharePoint

IE11 compatibility view emulator

This post describes how to figure out if IE11 has jumped in the compatibility mode and therefore screws up your CSS.

Compatibility view now and before

Microsoft has been pretty keen on introducing new ways to handle browser compatibility and make IE behave in even stranger ways that it usually does by switching it to compatibility mode. There are a few reasons this could happen, but perhaps the most usual one in SharePoint’s case is that IE identifies the SharePoint site to be located in intranet zone, or it’s set to that zone or the list of sites to display in compatibility mode via a group policy.

Before IE11 the switch was reasonably easy to notice – there would be a button/icon similar to this on the address bar, when the browser was in compatibility mode:

IE 10 compatibility mode

IE 10 compatibility mode

However, in IE11 Microsoft has removed the icon leaving us in the dark about whether the page is in compatibility mode or not. We COULD check the compatibility view and security zone settings to find out the mode, but there’s a better way, too. Now, we must check the developer tools (F12 brings them up) to see, which document mode is activated. IE11 in compatibility view may show us something similar to this:

IE11 compatibility view emulator

IE11 compatibility view (emulator)

But wait a minute – what if you can’t access the end user browsers yourself? Before it was pretty easy – you could just ask the end user to check for the compatibility view icon, as it was easily visible on the address bar, but nowadays you’re mostly out of luck – instructing the end users to actually use developer tools is probably going to be difficult. However, there’s a workaround for this.

Continue reading

Simplest way to create a thread on SharePoint

Stock photo from pixabay.com

This post describes the (probably) easiest and most straightforward way of creating a new Thread in your SharePoint (or any other .NET) server-side / desktop code.

Solution: how to create a Thread

Let’s face it – one should not create new Threads lightly when developing SharePoint solutions, but sometimes it’s difficult to avoid. This one time we were developing a pretty simple functionality, where we needed to create a few fields on a certain title when user activated a feature. However, because of the complexity of the environment, we encountered problems changing the title of the new field. Now, it’s usually pretty simple, but this time some other functionality, most likely developed by someone else, was changing it to the internal field name – which doesn’t look to good.

To be honest, we’re not even sure, why this worked. We suspected it might be because of the current culture of the thread, but changing it didn’t have any effect. Any way, we’re glad this worked, whatever the reason for that is.

How to properly use SPWeb.AllowUnsafeUpdates?

SharePoint2013

At times you may need to allow unsafe updates to SPWeb objects to get your code to run. This, in SharePoint C# code-behind is done by setting SPWeb.AllowUnsafeUpdates to true. However, as this is an exception to security settings, and should generally not be done, it’s a good practice to limit the change to as small a scope as possible – even though the setting is only persisted for the duration of the request (unless the SPWeb object was gotten from SPSite.GetWeb() or SPSite.Webs[]).

What to do?

I’ve found the easiest way to temporarily allow unsafe updates in a safe way but without too much of extra code to be this:

Please note, that it’s unwise to simply set the AllowUnsafeUpdates to false after the code, because there’s an ever-so-slight possibility of it screwing up some other code running in the same context at the same time! And of course, it’s likely to be unwise to allow unsafe updates if you’re handling data that was gotten as user input.