Microsoft Content Management Server - Global Search and Replace on Content

This is Interesting: Free IT Magazines  
Home > Archive > Microsoft Content Management Server > November 2004 > Global Search and Replace on Content





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Global Search and Replace on Content
mog

2004-11-10, 2:47 am

Colleagues,

We need to change all references to a deceased individual on our corporate
site. How can we perform a search and replace across all text content on the
MCMS site?

With kind regards,

mm
Stefan [MSFT]

2004-11-10, 2:48 am

Hi mm,

you need to write a script that enumerates all placeholders in all postings
in all channels and replaces the name.

Cheers,
Stefan.

--
This posting is provided "AS IS" with no warranties, and confers no rights.

MCMS FAQ:
http://download.microsoft.com/downl...6a/MCMS+2002+-+(complete)+FAQ.htm
MCMS Blog: http://blogs.msdn.com/stefan_gossner/category/4983.aspx
MCMS Sample Code:
http://www.gotdotnet.com/community/...t+S
erver

MCMS Whitepapers and other docs:
http://blogs.msdn.com/stefan_gossne...2/07/41859.aspx
--------------------------------


"mog" <mog@discussions.microsoft.com> wrote in message
news:4C9767A6-5B8F-4331-B78D-1DC6D0B3F8AC@microsoft.com...
> Colleagues,
>
> We need to change all references to a deceased individual on our corporate
> site. How can we perform a search and replace across all text content on

the
> MCMS site?
>
> With kind regards,
>
> mm



mog

2004-11-11, 5:50 pm

Thanks for the response.

I however am an unfortunate user of the system, two steps removed from the
consultancy which sold us this system. I must make a case for the
development.

A search and replace script would save us from days of tedious work. How
much work might writing a script involve? Is a script available that we can
modify?

Thank you.

m

"Stefan [MSFT]" <stefang@online.microsoft.com> wrote in message
news:uQDkzewxEHA.2752@TK2MSFTNGP11.phx.gbl...
> Hi mm,
>
> you need to write a script that enumerates all placeholders in all
> postings
> in all channels and replaces the name.
>
> Cheers,
> Stefan.
>
> --
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
> MCMS FAQ:
> http://download.microsoft.com/downl...6a/MCMS+2002+-+(complete)+FAQ.htm
> MCMS Blog: http://blogs.msdn.com/stefan_gossner/category/4983.aspx
> MCMS Sample Code:
> http://www.gotdotnet.com/community/...t+S
erver

> MCMS Whitepapers and other docs:
> http://blogs.msdn.com/stefan_gossne...2/07/41859.aspx
> --------------------------------
>
>
> "mog" <mog@discussions.microsoft.com> wrote in message
> news:4C9767A6-5B8F-4331-B78D-1DC6D0B3F8AC@microsoft.com...
> the
>
>



Stefan [MSFT]

2004-11-12, 2:47 am

Hi M,

around 2 hours.
Depends on the complexity (means if only specific postings or placeholders
should be looked at or all).

Cheers,
Stefan.

--
This posting is provided "AS IS" with no warranties, and confers no rights.

MCMS FAQ:
http://download.microsoft.com/downl...6a/MCMS+2002+-+(complete)+FAQ.htm
MCMS Blog: http://blogs.msdn.com/stefan_gossner/category/4983.aspx
MCMS Sample Code:
http://www.gotdotnet.com/community/...t+S
erver

MCMS Whitepapers and other docs:
http://blogs.msdn.com/stefan_gossne...2/07/41859.aspx
--------------------------------


"mog" <mojomcginley@hotmail.com.au> wrote in message
news:OxOP9vEyEHA.1188@tk2msftngp13.phx.gbl...
> Thanks for the response.
>
> I however am an unfortunate user of the system, two steps removed from the
> consultancy which sold us this system. I must make a case for the
> development.
>
> A search and replace script would save us from days of tedious work. How
> much work might writing a script involve? Is a script available that we

can
> modify?
>
> Thank you.
>
> m
>
> "Stefan [MSFT]" <stefang@online.microsoft.com> wrote in message
> news:uQDkzewxEHA.2752@TK2MSFTNGP11.phx.gbl...
http://download.microsoft.com/downl...6a/MCMS+2002+-+(complete)+FAQ.htm[vbcol=seagreen]
http://www.gotdotnet.com/community/...t+S
erver
[vbcol=seagreen]
on[vbcol=seagreen]
>
>



Alan Taylor

2004-11-25, 5:49 pm

Hi there,

here is a console app that I wrote that iterates though all postings,
checking the template type, and if it's the right type of template,
will modify the placeholder content that holds the metadata. This
might be useful to you with a few modifications.

using System;
using System.Xml;
using Microsoft.ContentManagement.Publishing;
using Microsoft.ContentManagement.Publishing.Extensions.Placeholders;

namespace CmsSetLastReviewed
{
/// <summary>
/// Summary description for SetlastReviewed.
/// </summary>
class SetlastReviewed
{
private const bool processPostingDesciption = false;
private const bool processNonNavigationPostings = false;

private const int numberOfMonthsToExtendExpiryBy = 3;

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// This application will set the lastReviewed date in all of the
pages in CMS below
// the root channel that are in "Published" or "Approved" state.
//
Console.WriteLine("Setting all lastReviewed Metadata Elements to
required format");
Console.WriteLine();

// Get the CMS application context.
CmsApplicationContext cmsContext = new CmsApplicationContext();

// Use this line to authenticate using current user.
// Must be in update mode to make changes to the system.
cmsContext. AuthenticateAsCurrentUser(PublishingMode
.Update);

//define start point
HierarchyItem startItem =
cmsContext.Searches.GetByPath("/Channels/MyIntranet");

if ((startItem != null) && (startItem is Channel))
{
Channel startChannel = startItem as Channel;
Console.WriteLine("Starting in channel: " +
startChannel.Path);

CrawlChannel(cmsContext, startChannel);
}
else
{
Console.WriteLine("Error: Could not retrieve starting
channel.");
}
}

private static void CrawlChannel(CmsApplicationContext cmsContext,
Channel currChannel)
{
DateTime dateToNeverExpire = Convert.ToDateTime("01/01/3000");

// First iterate through the postings, set the metadata and
approve the ones in the correct state.
PostingCollection postingColl = currChannel.Postings;

XmlPlaceholder pXml;

foreach (Posting thisPosting in postingColl)
{
if ((thisPosting.State == PostingState.Approved) ||
(thisPosting.State == PostingState.Published))
{
bool approvalRequired = false;

Placeholder MetaData =
thisPosting.Placeholders["MetaDataStore"];

if (MetaData is XmlPlaceholder)
{
pXml = MetaData as XmlPlaceholder;

if(pXml!=null && pXml.XmlAsString!=string.Empty)
{
string metaDataString = pXml.XmlAsString;

if (processPostingDesciption)
{
int positionOfTag =
metaDataString.IndexOf("UKMOD.description.description");
if (positionOfTag != 0)
{
int startPositionOfContentValue =
metaDataString.IndexOf("content=\"", positionOfTag + 1) +
"content=\"".Length;
int endPositionOfContentValue =
metaDataString.IndexOf("\" />", startPositionOfContentValue);

thisPosting.Description =
metaDataString.Substring(startPositionOfContentValue,
endPositionOfContentValue - startPositionOfContentValue);
}

approvalRequired = true;
}


// Process expiryDate
bool expirySet = false;
switch(thisPosting.Template.Name)
{
case "DocumentProfile":
case "TeamProfile":
case "DefenceNews":
case "BriefingNote":
case "PressRelease":
case "Images":
case "HowTo":
case "Operations":
case "LocationProfile":
case "BusinessProfile":
case "ApplicationToolProfile":
if (processNonNavigationPostings)
{
thisPosting.ExpiryDate =
thisPosting.ExpiryDate. AddMonths(numberOfMonthsToExtendExpiryBy
);
expirySet = true;

Console.WriteLine(thisPosting.Name + " (" +
thisPosting.Template.Name + ") set to expire on " +
thisPosting.ExpiryDate.ToShortDateString());
}
break;
default:
if (thisPosting.ExpiryDate != dateToNeverExpire)
{
thisPosting.ExpiryDate = dateToNeverExpire;
expirySet = true;

Console.WriteLine(thisPosting.Name + " (" +
thisPosting.Template.Name + ") set to never expire");
}
break;

}
if (expirySet)
{
DateTime aDate = thisPosting.ExpiryDate;
string expiryDate = string.Format("{0}-{1}-{2}
{3}:{4}:{5}",
aDate.Year.ToString("0000"),
aDate.Month.ToString("00"), aDate.Day.ToString("00"),
aDate.Hour.ToString("00"),
aDate.Minute.ToString("00"), aDate.Second.ToString("00"));

metaDataString = ChangeMetaTag(metaDataString,
"UKMOD.date.validEnd", expiryDate);
approvalRequired = true;
}

// Process lastReviewed
if (approvalRequired)
{
DateTime aDate = thisPosting.LastModifiedDate;
Console.WriteLine(thisPosting.Name + " last modified
set to " + thisPosting.LastModifiedDate.ToShortDateString());
string lastModifiedDate = string.Format("{0}-{1}-{2}
{3}:{4}:{5}",
aDate.Year.ToString("0000"),
aDate.Month.ToString("00"), aDate.Day.ToString("00"),
aDate.Hour.ToString("00"),
aDate.Minute.ToString("00"), aDate.Second.ToString("00"));

metaDataString = ChangeMetaTag(metaDataString,
"UKMOD.date.lastReviewed", lastModifiedDate);

if (approvalRequired)
{
pXml.XmlAsString = metaDataString;
thisPosting.Approve();
}
}
}
}
if (approvalRequired)
cmsContext.CommitAll();
}
}

// Now recurse through subchannels.
ChannelCollection channelColl = currChannel.Channels;

foreach (Channel thisChannel in channelColl)
{
Console.WriteLine();
Console.WriteLine("Searching channel: " + thisChannel.Path);
CrawlChannel(cmsContext, thisChannel);
}
}

private static string ChangeMetaTag(string metaDataString, string
tagToProcess, string replacementData)
{
const string tagEnd = "</properties>";
int positionOfTag = metaDataString.IndexOf(tagToProcess);
if (positionOfTag == 0)
// Tag doesn't exit within MetaTag so add it
metaDataString = metaDataString.Substring(0,
metaDataString.IndexOf(tagEnd)) + "<meta name=\"" + tagToProcess + "\"
content=\"" + replacementData + "\"/>\n" + tagEnd;
else
{
int startPositionOfContentValue =
metaDataString.IndexOf("content=\"", positionOfTag + 1);
int endPositionOfContentValue = metaDataString.IndexOf("\"
/>", startPositionOfContentValue);

string contentBefore = metaDataString.Substring(0,
startPositionOfContentValue);
string contentAfter =
metaDataString.Substring(endPositionOfContentValue);

metaDataString = contentBefore + "content=\"" +
replacementData + contentAfter;
}
return metaDataString;
}
}
}

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com