Month: September 2012

Sharepoint 2010 Custom Ribbon Actions Labels wont translate in Internet Explorer

Posted on Updated on

That’s actually not easy to find, but easy to fix, of course from Internet Explorer, it has nothing to do with Sharepoint, at least that is my current thinking I am glad to hear any comments on the matter.

Problem: We have custom actions in the ribbon, the name and description from these actions are coming from resource files. In Internet Explorer once you select the language, then in the ribbon you will see the correct language for the custom action labels. However if you then select a different language, you will see the labels for the language that it was set before that one. It doesn’t change.

How did I get to the solution: I checked all resource files and they were fine, we reset IIS, we executes stsadm –o copyappbincontent, we checked all feature receivers to see if there was some code conflicting with it

Then I decided to try in Google Chrome and in Mozilla Firefox. Well, the translations works fine there, so I thought it was a cache problem from the Internet Browser itself.

And Indeed its

Solution: Internet explorer Developer Tools, F12.

Add SPFieldMultiLineText html field by code wont show HTML Ribbon tools

Posted on Updated on

Well, this was a problem where I lost almost 2 days, and in theory it should just work.  Adding a field to a contenttype, set field properties, and then push down the changes to the lists.  Piece of cake, isnt it?  Well, it is, but not when you are adding a SPFieldMultiLineText and specially if you want that multiline to use FullHtml controls in the ribbon.

Well, if you ask me, an experience sharepoint and .net developer, this has to be a BUG from the product, there is no other explanation, and the issue is:

1. I added a spfield multiline, type: note to field collection

2. Then I added that field to a contenttype and pushed down the changes to the lists

3. The field gets added to all the lists, however, when the field has the focus, the ribbon tools, (bold, italic, etc), they just wont appear.

The explanation is:

Sharepoint sets the RichtText to False, when you are adding the field to the FieldsCollection of the web.

You have to set it AGAIN to true when adding it to the list, or after its added to the list.

This post helped me a little bit, even though, this posts talks about Publishing HTML fields, which are different, but the same thing happens:

The solution, I implemented was a little bit different to the post, because the field in a multiline rich text field is not HTML but Note.

Here is the code:

  /// <summary>
        /// Sharepoint after adding a multiline field to the fields collection, it sets the richtext back to false.
        /// </summary>
        /// <param name="strurl">Web url</param>
        /// <param name="liststr">List Name</param>
        private void processweb(string strurl, string liststr)
        {           
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite spsite = new SPSite(strurl))
                    {
                        using (SPWeb currentWeb = spsite.OpenWeb())
                        {
                            try
                            {
                                currentWeb.AllowUnsafeUpdates = true;
                                SPList list = currentWeb.GetSafeListByName(liststr);
                                SPField field;
                                for (int i = 0; i < list.Fields.Count; i++)
                                {
                                    field = list.Fields[i];
                                    //to work around a sharepoint defect ... make html fields work in richtext mode
                                    if (field != null && 
string.Compare(field.TypeAsString, "Note", true) == 0 &&
 (field as SPFieldMultiLineText).RichTextMode == SPRichTextMode.FullHtml)
                                    {
                                        (field as SPFieldMultiLineText).RichText = true;
                                        field.Update(true);
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                throw;
                            }
                            finally
                            {
                                currentWeb.AllowUnsafeUpdates = false;
                            }
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                throw;
            }
        }