Deleting ‘Rogue’ Documents/Pages from SharePoint Sites

When STSADM doesn’t pick up orphaned documents and you want to get rid of them from the content database…

DECLARE @pageName nvarchar(128)
DECLARE @dir nvarchar(256)
DECLARE @uid uniqueidentifier

SET @pageName = N’Holidays.aspx’
SET @dir = N’Resources/LocalInfo/TeamSiteFrance/Pages’

SELECT @uid = (SELECT [Id] FROM dbo.AllDocs WHERE LeafName = @pageName AND DirName = @dir)

DELETE [dbo].[AllDocStreams] WHERE [Id] = @uid

DELETE [dbo].[AllDocs] WHERE [Id] = @uid

DELETE [dbo].[AllUserData] WHERE tp_LeafName = @pageName AND tp_DirName = @dir

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: