Camlex 3.0 released

Hi, everyone!

I am glad to inform you that new version of Camlex – Camlex 3.0 – is released.

The major improvement to this version is Reverse Engineering – it allows to convert already existing CAML code to C# code.

Alexey Sadomov was the architect of this feature and the developer of it. I only helped him a little :-) Please, refer to Alex’s blog post for more details – Camlex.NET became bidirectional and goes online. Version 3.0 is released.

You can find Camlex project on Camlex Online site and CodePlex

Posted in Ideas for projects | Leave a comment

The DataSourceID of ‘TopNavigationMenu’ must be the ID of a control of type IHierarchicalDataSource

Hi, everyone!

Recently I faced another problem with SharePoint. At some moment, I got following error

where the exception says:

The DataSourceID of ‘TopNavigationMenu’ must be the ID of a control of type IHierarchicalDataSource. A control with ID ‘topSiteMap’ could not be found.”

Also SharePoint’s ULS log contained the similar text:

Application error when access /_layouts/settings.aspx, Error=The DataSourceID of ‘TopNavigationMenu’ must be the ID of a control of type IHierarchicalDataSource. A control with ID ‘topSiteMap’ could not be found. at System.Web.UI.WebControls.HierarchicalDataBoundControl.GetDataSource() at System.Web.UI.WebControls.HierarchicalDataBoundControl.ConnectToHierarchicalDataSource() at System.Web.UI.WebControls.HierarchicalDataBoundControl.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Well, I checked where that “TopNavigationMenu” control was located and found it inside “application.master” file:

So “SharePoint:AspMenu” control pointed to”asp:SiteMapDataSource” control. But wait, ASP.NET’s SiteMapDataSource DOES implement IHierarchicalDataSource in the reallity – so the error was irrelevant. Also there wasn’t any control with ID = “topSiteMap” in this “application.master” file. Further investigation showed that this master file had been previously  customized and OOTB content of it was:

and that OOTB’s “wssuc:TopNavBar” control was located in “~/_controltemplates/TopNavBar.ascx” file. The extraction of this file:

There is”SharePoint:AspMenu” control with ID = “TopNavigationMenu” pointing to “asp:SiteMapDataSource” with ID = “topSiteMap”. So it had all artifacts mentioned in the error (also please notice that “SiteMapDataSource” is located inside DelegateControl with ID = “TopNavigationDataSource“, so it could be overridden with some SharePoint feature; and, indeed, there are 2 features overriding it – OOTB’s “MySiteNavigation” and “Navigation” features activated with Publishing).

But it didn’t have any sense because “application.master” file was customized and  it didn’t refer to “TopNavBar.ascx” control located inside “ControlTemplates” folder.

So – what is the reason for error description pointing to “TopNavigationMenu” control and also complaining about absence of”‘topSiteMap” control? The direct answer is:

There is no reason for that. The description of error is totally (100%) misleading.

Now – how I fixed the problem. I looked into system’s Event Log and found that there are several errors like:

it reported that, for some reasons, a DLL couldn’t loaded into SharePoint’s WebApp. OK – I fixed all things like it, but the main error about mystical “topSiteMap” control was still here.

In system Event Log, there was another error:

Hmm, it said something for Safe Mode and that SharePoint couldn’t “enter” it.

Safe Mode is a mode of SharePoint when it make security checks and  allows only controls mentioned in “SafeControls” block of web.config file to be used on the pages.

Well, there is no any visible correlation between Safe Mode and the error; but I still fixed the problem with this DLL (it my case, I just deleted the reference to this control from “SafeControls” block of “web.config” file).

And, OMG, then the error disappeared!

So the real problem was with Safe Mode and not with Top Menu Navigation at all.

Hope, it helps.

Posted in SharePoint | Leave a comment

Resource files naming gotcha in SharePoint

Hi, everyone!

Just have come across another gotcha in SharePoint (though it appears also in pure ASP.NET) – related to file naming of resources inside “App_GlobalResource” folder.

I have a project which run-time resources are collected in (let’s say) “Parent.Child.resx” file. This file is deployed to “App_GlobalResources” folder of Web Application. Recently I have added rather independent part to the solution. The textual resources of this part are externalized into “Parent.Child.Subchild.resx” file. This RESX file is also deployed to “App_GlobalResources”folder.

Once I deployed component’s resource file, SharePoint stopped working and following exception was thrown:

The first marked text was ‘Resources.Parent’ and the second (grey-filled one) was “Child” – so the full text says:

“Compiler Error Message: CS0101: The namespace ‘Resources.Parent’ already contains a definition for ‘Child’”.

I tested the problem on MOSS 2007, SharePoint 2010 and Web Site created in pure ASP.NET 4.0 – the problem appeared everywhere when I uploaded “Parent.Child.resx” together with”Parent.Child.Subchild.resx” files into “App_GlobalResources” folder.

The textual description was rather cryptic, but Visual Studio helped a lot – it showed source C# files generated from RESX files.

So, the first resource file (“Parent.Child.resx”) compiles into following code:

And the second file (“Parent.Child.Subchild.resx”) compiles into following code:

So now everything became clear – in “Resource.Parent” namespace, there are:

  • “Child” class, created from  Parent.Child.resx file
  • “Child” sub-namespace (which is the first part of “Resources.Parent.Child” namespace), created from Parent.Child.Subchild.resx file.

The compiler is not happy about it and throws an exception.

To summarize – don’t create resource files which names are just the prefix of the names of other resource files.

Hope, it helps.

Posted in Ideas for projects | 1 Comment

New article – User Profile Synchronization issue

Hi, everyone!

Recently working on some issues in production environment, I got deeper understanding about how User Profile Synchronization works and some related issues – and wrote an article about it.

Please, enjoy – http://vtimashkov.wordpress.com/user-profile-synchronization-issue/ :-)

See you!

Posted in Ideas for projects | 1 Comment

Site page is not shown in IFRAME issue

Hi, everybody!

Today’s post is not about SharePoint, but rather about regular Web development.

Recently writing a website showing content of the other site in IFRAMEs, I met a problem. The page of some sites were normally shown inside IFRAMEs, while the pages of some other sites weren’t – IFRAME was just empty.

But the same pages (which was not visible inside IFRAME) were absolutely normally visible if I navigated to that pages in standard way typing the URL in browser address text box. Mystery!

The first example where I observed such strange behavior was Tech Net’s Blogs.

If you don’t believe me, please create simple HTML file with the only content:

<iframe src=”http://blogs.technet.com/”     style=”width:1000px;height:700px;”>

Now try to open the file in any modern browser. The content is either empty (Firefox’s behavior) or has some warning like “To help protect the security of information you enter into this website, the publisher of this content does not allow it to be displayed in a frame” (Internet Explorer and similar text with Opera).

It turned out that few years ago (if not months ago!), the browser producers added support for so-called “clickjacking protection” (see more details about it in the article “How To Fight Clickjacking (Using The Recent Twitter Hijacking As An Example)“). In few words – now browsers recognize “X-FRAME-OPTIONS” response header (with two possible values), and presence of this header in the response means that the page SHOULD NOT be shown in IFRAME.

So I needed somehow to ask the browser to ignore this response header. Unfortunately Firefox doesn’t have any option for it. So I had either to use some intermediary proxy like WebScarab, or to use Fiddler 2 asking it to remove undesired header.

I used the last one. There is documentation how to remove header from response stream in Fiddler 2. It worked like a charm.

UPDATE: Please notice, this approach works only on client side – so it is not possible to make a widely accessible site showing an arbitrary site in IFRAME if the latest site forbids showing itself in IFRAME using X-FRAME-OPTIONS.

In my case it worked, because I was the only user of my site.

Hope it helps!

Posted in Ideas for projects | 6 Comments

Impossibility to edit checked out documents in Microsoft Word

Hi, everyone!

I came across a bug in SharePoint 2010. Brief description:

It is not possible to edit in Microsoft Word checked out documents stored in SharePoint 2010 document library under credentials which are not your Windows credentials.

Usually I navigate across SharePoint 2010 sites and edit documents there using my own Windows account (I log into Windows under name “administrator”):

It is OK and works always perfectly.

But today, for testing purposes, I logged into SharePoint 2010 under different account using credentials of some test user named “TestProjectManager2″.

I navigate to the same site, to the same document library, uploaded new Word document inside it. Then I checked the document out. I did it being under test user account.

Then, when I tried to edit the document in Microsoft Word application:

I got a dialog telling me that the document being edited is checked out by different user (in fact, that “different” user was my test user account):

so Word opened the document in “Read-Only” state. WTF!!!

I believe it happens because the document is marked in SharePoint 2010 as checked out by test user, while Microsoft Word is running under my Windows account:

So Microsoft Office sees the difference and reports it as an issue.

Hope, it helps!

Posted in SharePoint | 2 Comments

A way to customize forms of a SharePoint list

Hi, everybody!

There are several approaches to customize NEW/EDIT/VIEW forms of a SharePoint list.

  • Firstly, you could use SharePoint designer and to customize needed form “in-place”. Such approach has obvious disadvantages – it is just not reusable.
  • Second, you could employee Rendering Templates. It is goes alone with SharePoint best practices, but it has many disadvantages too – like impossibility to insert your custom control into the middle of ListFormWebPart.
  • Etc, etc, etc.

I would like to show additional way – flexible enough to be considered when there is a need to customize NEW/EDIT/VIEW form of a list. The final result will look like in my case:

As you can see in the form, in standard MultipleLookupField control there is additional server-side button.

As you know, each SharePoint list has several forms which are standard ASP.NET pages. The form to add new list item is “NewForm.aspx” page, the form to edit a list item is “EditForm.aspx” and the form to view a list item is “DispForm.aspx”.

In the terms of SharePoint API, they are SPForm class’s instances.

Each of these forms, has a Web Part Zone with name “Main”; inside this Web Part Zone there is only Web Part – ListFormWebPart. But it is possible to add you own Web Part implementing needed business functionality!

So my steps were:

1. I created a Web Part to be added on EDIT form of certain list. At the moment, the Web Part didn’t do anything useful – just stub code.

2. I added this custom Web Part to the main WebPartZone:

var form = list.Forms[PAGETYPE.PAGE_EDITFORM];
using (var manager = web.GetLimitedWebPartManager(
       form.ServerRelativeUrl, PersonalizationScope.Shared))
{
    manager.AddWebPart(new CustomWebPart(), "Main", 0);
}

3. In OnInit() event of the custom WebPart, I created additional button and added it near MultipleLookupField control:

protected override void OnInit(System.EventArgs e)
{
    FindControlEx(Page); // hack !!!
    var coll = SPContext.Current.FormContext.FieldControlCollection;

    var lookup = coll.Cast()
        .Where(x => x is MultipleLookupField)
        .Select(x => (MultipleLookupField)x)
        .FirstOrDefault();

    if (lookup != null)
    {
        var button = new Button { Text = "Update Test Steps!" };
        lookup.Parent.Controls.Add(button);
        button.Click += OnButtonClicked;
    }

    base.OnInit(e);
}

4. There is small hack – in OnInit event, code retrieving fields on the form

var coll = SPContext.Current.FormContext.FieldControlCollection;

doesn’t find anything. So I had to force creating controls by FindControlEx() function (and call it before):

private static void FindControlEx(Control rootControl)
{
    foreach(Control control in rootControl.Controls)
        FindControlEx(control);
}

5. In Click event of the button, I wrote needed business code modifying next field named “Test Steps” – but it doesn’t matter for the article.

6. Profit!

Hope it helps.

Posted in SharePoint | 2 Comments

How to visualize detailed exception information

Hi, everyone!

Usually in SharePoint 2010 you can’t see exception information directly on the page. Instead of it, you can see something like this:

Basing on Correlation ID you can make a search across SharePoint ULS log files and find the reason. It is great, but a little annoying.

To enable showing detailed exception information directly on the page, you have to change few lines in “web.config” file:

SharePoint -> SafeMode -> CallStack = "true"
System.Web -> CustomErrors -> Mode = "Off"

After it, you can see detailed exception information:

So there is stack trace and all details about exception.

But is some cases, I faced a problem when I still didn’t see detailed exception information:

There was a complain that I had to assign mode of CustomErrors element to “Off” value. But I already did it!

I looked at source address of this page:

and I saw that it was layout page. I navigate to LAYOUTS folder inside 14 hive of SharePoint and, to my surprise, I found there another web.config file:

And it contained wrong value for CustomErrors element:

After I altered this web.config, then I was able to see full information about the exception.

Thanks for reading!

Posted in SharePoint | Leave a comment

IE’s “Continue to this website (not recommended)” missing

Hi, everyone!

One another stupid problem.

When I try to connect to HTTPS site with invalid SSL certificate, then usually IE shows a dialog asking whether I trust this site or not. Then I click “Continue to this website (not recommended)” and navigate to the target site:

It is OK.

But recently I found that I am not able to click this link, just because it was absent:

What an awful “perdit monokle”!

After some googling, the answer came to my hand – I had to synchronize my computer’s clocks – it was 3 minutes behind real time! So when I set correct time, then IE misbehavior disappeared.

Thanks for reading!

Posted in SharePoint | Leave a comment

Synchronization Issue of Choice field inside Microsoft Word

Hello, everyone!

A story about just another SharePoint gotcha :-)

I had a custom site field basing on Choice field type. Rather casual one from the first look:

<Field ID="{7BC2F319-F0BA-4BD4-8D64-2ECE3A88EF73}"
   SourceID = "http://schemas.microsoft.com/sharepoint/v3"
   Name="FileStatus"
   StaticName="FileStatus"
   DisplayName="$Resources:atB_Extra_Localization,FileStatus;"
   Type="Choice"
   Format="Dropdown"
   FillInChoice="FALSE"    
   Required ="FALSE"
   Hidden ="FALSE"
   Sortable ="TRUE"
   Group="$Resources:atB_Extra_Localization,MetaInformationSiteColumns;">
  <CHOICES>
    <CHOICE>
      $Resources:atB_Extra_Localization,FileStatus_Approved;
    </CHOICE>
    <CHOICE>
      $Resources:atB_Extra_Localization,FileStatus_ForReview;
    </CHOICE>
    <CHOICE>
      $Resources:atB_Extra_Localization,FileStatus_InProgress;
    </CHOICE>
    <CHOICE>
      $Resources:atB_Extra_Localization,FileStatus_Frozen;
    </CHOICE>
  </CHOICES>
  <Default>$Resources:atB_Extra_Localization,FileStatus_InProgress;</Default>
</Field>

Looks very simple, isn’t it? Indeed it is simple and working site column. But when I tried to add this site column to a document library – I got a problem.

When a new document was uploaded to the document library, everything was OK – I assigned needed value to all properties including this Choice field. But when I tried to update the document through Microsoft Word, then I got following problem:

Word said that there is a problem with required field (my Choice field wasn’t Required – so the error was misleading!). When I tried to save the document, I got a error dialog:

The dialog informed “The file cannot be saved because some properties are missing or invalid” and it had a button to open Document Information Panel. I clicked the button  and Document Information Panel opened:

As you can see there is no required fields, but two fields are shaped with strange red dotted border (the second field was quite similar to the first one, so I omitted its definition for brevity). It was strange – because other fields had the values which I assigned during uploading the document to the document library, while these two fields were empty even I had assigned values to them too.

The problem was even worse, that it was impossible to assign values in Document Information panel. So to save the document, I had to go to Information view of the document and assign the values there:

Well, after I assigned values there, it was possible to save the document back to SharePoint.

But every time  I changed list item’s properties in OOTB’s EDIT form, then the problem with fields inside Word appeared again.

The problem was somehow related to synchronization between SharePoint list item’s properties and Word’s shadow copies of these properties inside .DOCX file. The synchronization did work for these Choice fields while for all other fields synchronization worked perfectly.

After some investigation, the reason was found. The definition of my site column contained options in form:

<CHOICE>
  $Resources:atB_Extra_Localization,FileStatus_Approved;
</CHOICE>

while the correct form should be:

<CHOICE>$Resources:atB_Extra_Localization,FileStatus_Approved;</CHOICE>

Each option should have one line without NewLine/CarriageReturn characters.

After I fixed my site column’s definition, everything started working correctly.

Thanks for reading!

Posted in SharePoint | Leave a comment