Unanswered: setting the properties of udl file by script
I am creating udl files by a script for all our websites.Now I have stucked at one point.I am wondering how can i set the properties of udl file by script.
I need to specify the following properties for the script and place it after
'set properties of udl
set fsobj = server.CreateObject("Scripting.FileSystemObject")
set getfsobj = fsobj.OpenTextFile("E:\TEST\testing.txt")
while not getfsobj.AtEndOfStream
line = getfsobj.ReadLine
line = split(line,":")
name = trim(line(0))
effectively you are just writting a text file yeah? it might have a different extension (.udl) but it is just plan text.
So why can't you read in the file (similar to what you are doing). Find the properties you want to change. Replace them and write them back out.
Effectively your file is a collection of value pairs eg X=123;Y=345;Z=234
So I would do something like this.... read in each line and add for each line split it on the semi colon to get your value pairs, then split each value pair on the equals sign to get a name and a value. If the name is one of the ones you want to replace change the value. Then rewrite the line based on the new value pairs....
Dim fso, f1, ts, s
Const ForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject")
Set orginalTS = fso.OpenTextFile("c:\orgfile.udl", ForReading)
Set newTS = fso.CreateTextFile("c:\newfile.udl", true)
do while orginalLine<>""
newLine = ""
valuePairs = split(orginalLine,";")
for i = 0 to valuePairs.UBound ' might need ubound-1
pair = split(valuePairs(i),"=")
if pair.Ubound = 2 then ' we have a valid value pair to check
name = UCase(pair(0))
namevalue = pair(1)
if name = PROVIDER" then
pair(1) = newProvider
valuePairs(i) = pair(0) & "=" & pair(1)
newLine = newLine & valuePairs(i)
orginalLine = orginalTS .ReadLine
Set fso = nothing
Set orginalTS = nothing
Set newTS = nothing
That should be pretty close I think.... I haven't tested it at all. There are a couple of comments there that you might want to check on. The area I have bolded is where you would add the other names of value pairs to replace. You could use a case statement here if you wanted.