Friday, February 29, 2008

Incompatible Web Part markup detected. Use ".dwp web part XML instead of *.webpart web part xml

I'm on MOSS 2007 and just developed this web part deriving from Microsoft.SharePoint.WebParPages.WebPart.  It works fine if I manually deploy it to MOSS, that is, manually copy the DLL and add the SafeControl entry into web.cnofig, and then add it in the web part gallery.   

If I package it up in a solution .wsp file,  adding the solution, deploying it, and activating it all work fine.  However, when I go to the home page and try to add it, I get this popup js alert message:

Unable to add selected web part(s).

<web part name>: Incompatible Web Part markup detected.  Use ".dwp web part XML instead of *.webpart web part xml.

 

_________________________________________________

How i solved it?

 

I fixed it by inheriting from

System.Web.UI.WebControls.WebParts.WebPart and deployed it successfully.

Friday, February 22, 2008

Creating a SpFieldUser Field in Sharepoint

 

I was trying to use the list.Fields.Add method to add a SpFieldUser field but i didn't found information on how to do it.

But the below boxed info helped me to create it in another way.

 

How to add a User Information lookup field with code

One of our developers asked me a question about adding a lookup field to the "User information" list with code. The "Add" method of SPFieldCollection wants a Guid for the destination list, but the "User information" list is not a SharePoint list. The solution is to use the "AddFieldAsXML" and submit a field XML instead.
SPWeb web = GetContextWeb(Current) 'Or whatever method used to acquire this object
SPList list = web.Lists[<listname>];
list.Fields.AddFieldAsXml("<Field Type="User" List="UserInfo" ShowField="Title" DisplayName="<FIELDNAME>" Name="<FIELDNAME>" />");

Tuesday, February 12, 2008

Adding a button on a Sharepoint web part

 

private string MessageButtonTreeClick="";

// Declare variables for HtmlControls user interface elements.
public void mybtnSearch_click (object sender, EventArgs e)
{
    MessageButtonTreeClick += "ButtonClicked";                
}

 

_______________________________________________

// Override the ASP.NET Web.UI.Controls.CreateChildControls

// method to create the objects for the Web Part's controls.

protected override void CreateChildControls ()

{

//Create a Search Button

mybtnSearch = new HtmlButton();

mybtnSearch.InnerText = "Search...";

mybtnSearch.Attributes.Add("width","75px");

mybtnSearch.ServerClick += new EventHandler ( mybtnSearch_click );

myTableCellControls_btnSearch.Controls.Add(mybtnSearch);

}

 

_______________________________________________

public class Tree : Microsoft.SharePoint.WebPartPages.WebPart

{

HtmlButton mybtnSearch ;

}