The file format is not valid.Try importing a webpart file(.WebPart)

May 28, 2012 at 1:11 PM

hi guys.

i m trying to use fluent ribbon in my sharepoint site. i ve added a web part to my visual studio share point project and i ve overrided the GetTabDefinition method. and my web part inherited from RibbonControl class.

i followed this article to achieve this. But when i try to add my web part to the page i got this error.

i tried different ways this is one of them. if required i can explain other ways that i tried.

Is anyone help me what i m missing here ?

May 28, 2012 at 1:49 PM

Hello, ugurcerci!

You shouldn't inherit your webpart from RibbonControl. RibbonControl is not a webpart, it is merely a user control.

If you want to get a webpart with contextual tab (i.e. which is hidden by default, and is shown only when your webpart is selected), then inherit your webpart from the ContextualWebPart class.

If you want to have a static tab on a page with the webpart, then you can inherit your webpart from  the standard WebPart class, and then use RibbonController.AddRibbonTab method to add a static tab. You can call this method from OnPrerender event handler.

Please, do not hesitate to ask any additional questions!

May 29, 2012 at 7:39 AM

thanks for answer omlin.

but when i inherit my web part from standard webpart class i cant override GetTabDefinition method. then i replace webpart to ribboncontrol class this time i got this error 'the file format is not valid. try importing a webpart file(.WebPart)

Also OnPreRender method i cant call RibbonController.AddRibbonTab. but i can use RibbonController.Current.AddRibbonTabToPage method. And it takes 3 argument. first argument is tabdefinition, second is page and third one is a bool value called makeInitial.

what can i do now?

Best Regards.

May 29, 2012 at 8:04 AM

me again omlin.

i also wanna ask that about contextual tab. you said about it "which is hidden by default, and is shown only when your webpart is selected". but i want it is shown without selecting my webpart. because i want to use my webpart changing it chrome type to 'none'. but this time i couldnt see my contextual webpart.

is this possible to make it this way?

thanks again.

May 29, 2012 at 8:17 AM
Edited May 29, 2012 at 8:21 AM

You don't need to override anything if you use RibbonController.

Code for a webpart with static ribbon tab should look something like this:

public class MyDashboard : WebPart
    // Visual Studio might automatically update this path when you change the Visual Web Part project item.
    private const string _ascxPath = @"~/_CONTROLTEMPLATES/DeskWork/TasksDashboard/TasksDashboardUserControl.ascx";

    protected override void CreateChildControls()
        Control control = Page.LoadControl(_ascxPath);

        var myTabDefinition = new TabDefinition()
            Id = "MyTab",
            Title = "My tab",
            Groups = new GroupDefinition[]
        RibbonController.Current.AddRibbonTabToPage(myTabDefinition, this.Page, true);



May 29, 2012 at 8:30 AM

thanks omlin this works great :)

do you know anything about my last question? about contextual tab?