Create a Page in SharePoint sub site is not adding to the sub site but the Root site

I hope the post title did not confuse you. I hit this weird behaviour in SharePoint when I was in “www.sharepoint.com/subsite” trying to create a Page in “www.sharepoint.com/subsite/pages” library. The dialog shows URL of Root Site in “Find It at”

create a page not adding to correct site 1

If you proceed to create the page, it will be added into ROOT SITE! which is not what I wanted

Resolution

To avoid confusing and to make the “add a page” adds pages to the correct site. Please do the following:

  1. Go to your sub site setting page
  2. Go to “Navigation” under look and feel section
  3. Uncheck the field “
  4. Click “OK” an save

Once you have unchecked the field, your “add a page” is now adding to the correct subsite!

 

Parse Error in SharePoint Page Layout

If you ever bumped into this issue when your custom SharePoint Page Layout cannot be rendered properly. You may try the resolution steps below

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: Only Content controls are allowed directly in a content page that contains Content controls.

In SharePoint branding journey, you often need to create your custom page layout to present your article base on Designer’s template file.

And if you are doing it, there is 1 important thing that you should Avoid doing. And that is to Auto Formatting your PAGE LAYOUT!

If you have not noticed (probably you haven’t because you found my article!)

Once you auto formatting your Page Layout via Visual Studio function  CTRL + E + D

<asp:content contentplaceholderid=”PlaceHolderPageTitle” runat=”server”>

See clearly, there is a problem with the Tag above. the “c” for content is auto formatted to be lower case! It matters! Lower c and Upper C make a huge different! It took me one whole one to try out and fix this issue!

Resolution

If you want to make use of the auto formatting (to tidy up your code) please remember to REPLACE ALL (CTRL + H) for “asp:content” to “asp:Content”. Make sure your match case is checked when replacing all

replace all match case page layout error

Jeez!

 

How to Swing SharePoint to a new (clone) Config DB after Restoring from Backup

I have a request to get a restored SharePoint 2010 up for some recovery. The existing SharePoint is still running while having its same Image restored to a separate Server, the first key important thing is that the cloned Server should not have the same Host Name as per the existing one.

Once you boot up the cloned Server, the HostName is changed and you will hit Error when connecting to SharePoint configuration server.

So, if you run SharePoint Product Configuration Wizard, You will hit error again saying you cannot connect to existing Config DB. Simply because your cloned server is still pointing to OLD Config DB (OLDHOSTNAME\SQLInstance).

Resolution

What you can only do! (as far as i know!) is to run the following STSADM comment

stsadm.exe -o setconfigdb - -databaseserver "<DatabaseServer>" -farmuser "<DOMAIN\YourFarmAccount>" -farmpassword "<YourFarmAccount Password>"

Once its done, rerun SharePoint Product Configuratino Wizard…

SharePoint Installation Error – Requires .NET Framework 4.5 despite having .NET Framework 4.6

I was puzzled when trying to install SharePoint 2013 in Windows 2012 R2. For the past few months when I was doing the same steps, this error did not occur.

If you have done Prerequisite Installation and trying to install SharePoint 2013, You MAY encounter this error message

Setup is unable to proceed due to the following error(s):

This product requires Microsoft .Net Framework 4.5.

Net 4.6 error when installing SP2013

Having checked in your registry stated here, my .net framework was 4.6 (huh? isn’t 4.6 is better and higher version than 4.5 that’s required?)

Yea, so the installer does have a little issue if we have Higher version of .Net Framework.

Resolution

They underlining issue for this is that the Windows 2012 R2 provisioned is pre-installed with .NET Framework 4.6

To undo this 4.6 version, you would have to go to your Control Panel and uninstall the KB3102467 Windows Update

uninstall sharepoint kb .net 4.6

SharePoint Custom Solution Branding and Tips – Part 2

This is part 2 on how to brand your SharePoint Solution. If you haven’t read my part 1, please do so here.

Often than not, you would want to include your custom List Definition/Instance to be provisioned into your Solution file. In SharePoint 2013, they’ve changed the Site Content page drastically and you can’t really Ignore the BIG BIG icon for each List/Library within your site.

sharepoint site content list icon image

It’s fancy and it’s sleek. So how can I create one for my own solution?

As usual, there isn’t gonna be much documentation provided in MSDN. And most of the time, you just got to crack your head and dig your way out. I’m writing this post here so that you can at least Find my article when you’re googling around.

How to set Image for your List Definition / List Instance

Assuming you have already created a SharePoint 2013 Project solution and added a List Definition.

Add SharePoint “Images” mapped folder into your Project as shown below

right click add image layout folder sharepoint

Prepare TWO icons and you must ensure that the following rules are followed:

  1. Both icons must have same file extension.
  2. One icon is in 16×16 pixel size and the other one is in 96×96 pixel size
  3. File Name of the 16×16 icon must starts with small I: “it” e.g. itmyfancyicon.png
  4. File Name of the 96×96 icon must starts with small L: “lt” e.g. ltmyfancyicon.png
  5. Both file names must be exactly the same except for the first character.

To better helping you to understand, I’m including the two images used below

itmyfancyicon.png itmyfancyicon  (16×16)                  ltmyfancyicon.png ltmyfancyicon (96×96)

After meeting these rules, you need to include them into the Images mapped folder and be placed into the same Folder. (Must)

sharepoint list icon image same folder

Lastly, go to the Elements.xml file of the list definition and modify the Image Attribute to point to “it” (16×16 pixel size) image as shown below. DO NOT specify the one that starts with “L”.

http://wp.ahcheng.com/wp-content/uploads/2016/01/sharepoint-list-definition-image-url-attribute.png

Once you specified to the small “i” image, deploy it and you should see your List is having a nice and Correct images!

http://wp.ahcheng.com/wp-content/uploads/2016/01/sharepoint-list-definition-image-how-to-set-it-properly.png

 

 

PowerShell script to disable Limited Access Lock Down mode for all Site Collections

I always like to make use of PowerShell to do stuff. When dealing with a lot of Site Collection, it is advisable to script your task than going through UI one by one to configure.

I have a requirement to take out the Limited Access Lock Down mode introduced in SharePoint 2013. A bit introduction for this feature, this feature actually BLOCK users from browsing a file (via Browser) or check-in/check-out a file (via Office Client such as Word).

limited access user permission lockdown mode

If you activate this lock down mode, SharePoint does not allow browsing of its parent and hence you will receive error when trying to edit a file via Office Client (even if you have contribute permission to the file itself!). If you are only allowing your users (usually external or someone who does not have permission to the entire web or document library) to read the file, you do not need to Deactivate this.

In my environment, its much more complicated where some users are only editable to file from other Sub Site or Site. And Content Owners always assign Individual file for other site’s user to edit. In this case, in order to allow seamless experience, I would need to make sure that this feature is Deactivated at all site collections.

I came out with this PowerShell, Short and Sweet one, to help me. Hope it helps!


Get-SPSite | % {
  Get-SPFeature -Site $_ | ? { $_.DisplayName -eq "ViewFormPagesLockDown"} | Disable-SPFeature -Url $_.Url -Confirm:$false
}

P.S. Run it via SharePoint Management PowerShell. Or else you need to add in “Add-PSSnapIn Microsoft.SharePoint.PowerShell” at the start of this script.

EditorPart does not have an ID

Yet another error that I’ve encountered when customizing ToolPart (aka EditorPart) for my own SharePoint Web Part.

The task is to create a custom tool part with custom control that displays a list of SharePoint Lists. This custom control contains a post back logic to update another drop down list base on the selected value.

In order to display your toolpart into the Web Part properties pane, you would need to override the following virtual method in System.Web.UI.WebControls.WebParts.WebPart class


public override EditorPartCollection CreateEditorParts()

I bumped into this error “EditorPart does not have an ID” with the following code that was not done correctly


public override EditorPartCollection CreateEditorParts()
{
 ArrayList editorArray = new ArrayList();
 MyEditorPart part = new MyEditorPart() { ID = this.ID + "_editorPart1" };
 editorArray.Add(part);
 editorArray.Add(new WebPartToolPart() );
 editorArray.Add(new CustomPropertyToolPart());
 EditorPartCollection editorParts = new EditorPartCollection(editorArray);
 return editorParts;

}

The use of including WebPartToolPart and CustompropertyToolPart is to ensure that your custom web part would still display the OOTB Web Part Properties pane (which has the functionality to change Height, Width, ChromeType etc etc)

To use them correctly, you would need to specify an ID for each of the class. After applying the code below, the error is gone.


public override EditorPartCollection CreateEditorParts()
{
 ArrayList editorArray = new ArrayList();
 MyEditorPart part = new MyEditorPart() { ID = this.ID + "_editorPart" };
 editorArray.Add(part);
 WebPartToolPart wpToolPart = new WebPartToolPart() { ID = this.ID + "_wpToolPart" };
editorArray.Add(wpToolPart);

 CustomPropertyToolPart cpToolPart = new CustomPropertyToolPart() { ID = this.ID + "_cpToolPart" };
 editorArray.Add(cpToolPart);
 EditorPartCollection editorParts = new EditorPartCollection(editorArray);
 return editorParts;
}

A Web Part or Web Form Control on this Page cannot be displayed or imported. The type could not be found or it is not registered as safe.

This is a very common error that SharePoint Developers often face. As stated in the error message, this is due to SafeControl Elements in Web.Config file of your SharePoint Application not being added correctly, or perhaps pointing to the wrong type name.

Resolution

To solve this issue, you’ll need to make sure that the SafeControl Entries in your SharePoint solution projects is configured correctly.

Step 1 – Find out what is the correct type name.

  1. Navigate to your .webpart file in Visual Studio that you’ve misconfigured.
  2. Double clicking it to open the webpart file.
  3. Copy the Type Name and exclude the last node
    web part register 1
  4. Alternatively, go to your web part .cs file and copy the Namespace
    web part register 2

Now that you have the correct type name. You need to…

Step 2 – Specify the right Safe Entry

  1. Click on the Web Part
  2. Under Properties panel, click on the … icon beside Safe Control Entries
    web part register 3
  3. Enter the value found in Step 1 into Namespace field as shown below.
    web part register 4
  4. Deploy and Done!

PowerShell script to Open or Close SharePoint Web Parts

If you ever need to make changes to your SharePoint Web Parts such as hiding/showing, this post will help you to cut down unnecessary time.

Run the PowerShell script below via SharePoint Management Shell.

Change the Parameter accordingly base on your environment.


$web = Get-SPWeb [URL]
$f = $web.GetFile("Pages/Default.aspx");

if( $f.CheckOutStatus -eq "None" )
{
  $f.CheckOut();
}
$wpm = $f.GetLimitedWebPartManager("Shared")
$webParts = $wpm.WebParts | ? {$_.GetType().Name -eq "ContentEditorWebPart"} //Change for your own web part type
if($webParts.GetType().Name -eq "Object[]")
{
  $webParts | % {
    #$wpm.CloseWebPart($_);
    $wpm.OpenWebPart($_);
    $wpm.SaveChanges($_);
  }
}
else
{
  #$wpm.CloseWebPart($webParts)
  $wpm.OpenWebPart($webParts)
  $wpm.SaveChanges($webParts)
}

$f.CheckIn("");
$f.Publish("");

The example above will check if the page is check out before making any changes to the web parts. Subsequently, it closes/opens all content editor web parts within it and check in and publish the page. You can additional perform more tasks such as DeleteWebPart or AddWebPart, MoveWebPart or only make changes to only certain type of web part by changing PowerShell rules