Mass Update ASPX Pages

techfuzz

Diamond Member
Feb 11, 2001
3,107
0
76
A long time ago I designed a corporate intranet using plain ASPX pages. Fast forward about 6 years and I need to update all the pages to use Master Pages. We're looking at about 225 pages that need to be converted. Besides the obvious brute force method of changing each page, are there any tools available to perform a mass update all at once?

techfuzz
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
It would be easy enough to do a mass edit to add the @master attribute to the header, but what about the content declarations? Is every existing .aspx page going to fit entirely into a single content placeholder on the master?
 

techfuzz

Diamond Member
Feb 11, 2001
3,107
0
76
No, the existing ASPX files are all designed around the same template-a badly conceived table structure (shudder). The mass update would have to strip the <html> up to a point below the <body> tag. Then of course it would need to insert the contentplaceholder tags around the following section up to a point just before the </body> tag. What I need is some kind of macro/reg-ex search and replace tool. I'm doubting such a thing exists unfortunately.

I'm thinking a staged rollout approach is going to be needed in order to pull this off using a manual editing effort. I really didn't want to spend weeks do this... Argh!

techfuzz
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
If your HTML documents are formed properly and since you said they are all from the same template I don't see any reason why a shell script using tools such as grep and awk can't do it. If not, a perl/python/ruby script could handle it with ease.
 

Reel

Diamond Member
Jul 14, 2001
4,484
0
76
Originally posted by: Crusty
If your HTML documents are formed properly and since you said they are all from the same template I don't see any reason why a shell script using tools such as grep and awk can't do it. If not, a perl/python/ruby script could handle it with ease.

My first thought.
 

techfuzz

Diamond Member
Feb 11, 2001
3,107
0
76
Originally posted by: Crusty
If your HTML documents are formed properly and since you said they are all from the same template I don't see any reason why a shell script using tools such as grep and awk can't do it. If not, a perl/python/ruby script could handle it with ease.
Since this is Windows-based, shell scripts are not possible especially since I have little knowledge of how to use grep or awk.

techfuzz
 

Noobsa44

Member
Jun 7, 2005
65
0
0
Just so you know, windows does have grep. In addition to that, almost all windows boxes support VB Script and Jscript, so you could always write a simple search and replace script.

While this isn't exactly what you want, this is a simple search VB Script I wrote some time ago which might get you started in the right direction:

'Just copy code and save it in a .vbs file.
Set fs = CreateObject("Scripting.FileSystemObject")
aFolder = InputBox("Enter the folder you wish to search for a key phrase (not recursive)","","C:\Development\")
if(instr(Right(aFolder,1),"\")=0) then
aFolder = aFolder & "\"
end if
Phrase = InputBox("Enter the phrase to search for.","","hello world")
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(aFolder)
Set fc = f.Files
For Each f1 in fc
if(lcase(right(f1.name,3))=".cs") then'filters out for c# files.
on error resume next
tmpData = SearchFile(aFolder & f1.name, lcase(Phrase))
if(err.number<>0) then
MsgBox "error with: " & f1.name
end if
on error goto 0
if(tmpData<>"") then
MsgBox "File: " & f1.name & vbNewLine & _
"Data: " & vbNewline & _
tmpData
end if
end if
Next

MsgBox "Done!"
'functions
Function SearchFile(File,Phrase)
Set f = fs.OpenTextFile(File,1,-2)
aWholeDoc = f.readAll
f.close
set f = nothing
Doc=ConvertToArray(Split(aWholeDoc,VbNewLine))
info=""
For i = 0 to UBound(Doc)
line = Doc(i)
if(instr(1,LCase(line),Phrase)>0) then
info=info & CStr(i+1) & " - " & line & vbnewline
end if
next
SearchFile = info
End Function

Function ConvertToArray(PossibleArray)
if(isArray(PossibleArray))then
ConvertToArray=PossibleArray
else
ConvertToArray=array(PossibleArray)
end if
End Function