Wednesday, May 30, 2012

A Web Part with this ID has already been added to this page

Recently I was playing with adding webparts programatically.

Then I got this error "A Web Part with this ID has already been added to this page"

tried to use contents=1, but no use . it says page could not found

finally found the below link

http://dpruna.blogspot.com/2011/11/web-part-with-this-id-has-already-been.html

Thanks to author.


using the following procedure we can find out the webparts added to the given page.

Note:- it contains webparts added by all the users. (Not only you)

it gives you list of webparts added to that page (problamatic duplicate webparts aswell). Then you know what to do.

delete the webpart wisely

if it is dev server then may be less issues, but if it is Production server.........be careful

Here is the procedure.

Note:- My list exists in subsite ("ABC"). So I had to use @DocDirName = N'ABC/Lists/Raportari',


declare @DocDirName nvarchar(255),
        @DocLeafName nvarchar(255),
        @SiteId uniqueidentifier,
        @DocId uniqueidentifier,
        @DocParentId uniqueidentifier,
        @Level int
 
select  @SiteId = '88501D83-5339-4745-827F-0C7454F9B7BD',
        @DocDirName = N'Lists/Raportari',
        @DocLeafName = N'EditForm.aspx',
        @Level = 1
 
SELECT TOP 1  
    @DocParentId = ParentId,  
    @DocId = Id  
FROM  
    TVF_Docs_NoLock_Url(@SiteId, @DocDirName, @DocLeafName) AS Docs  
 
SELECT  
    WP.tp_ID,  
    WP.tp_WebPartTypeId,  
    WP.tp_Assembly,  
    WP.tp_Class,
    WP.tp_SolutionId,  
    WP.tp_AllUsersProperties,    
    WP.tp_WebPartIdProperty,
    WP.tp_Version,  
    WP.tp_Cache,  
    (N'{' + CAST(WP.tp_ListId AS nvarchar(36)) + N'}') AS tp_ListId,  
    WP.tp_Type,  
    WP.tp_Source,  
    WP.tp_BaseViewID,  
    WP.tp_View,  
    WP.tp_CreationTime  
FROM  
    AllWebParts AS WP WITH (INDEX=PageUrlID_FK)
WHERE  
    tp_SiteId = @SiteId AND  
    tp_IsCurrentVersion = CONVERT(bit, 1) AND  
    tp_PageUrlID = @DocId AND  
    tp_PageVersion = 0 AND  
    tp_Level = @Level

No comments:

Post a Comment