PDA

View Full Version : Setting web.config


beezwiser
07-16-2005, 07:31 AM
As part of my setup, I ran a web install script that installs a virtual directory and a dot.net web application. This application has a web.config file that contains a string @@CONNECTSTRING@@ that I want to replace with a data connect string. I can set up the form with the database server, user name, password, and database, but need to find this file after it has been installed on the web server and edit this file by replacing the above placeholder with a valid connect string.

I can't see how to do this in setup factory?

HELP.

Adam
07-18-2005, 10:09 AM
To find the file and get the path to it use File.Find (http://www.indigorose.com/webhelp/suf70/Program_Reference/Actions/File.Find.htm)

To dump this file to a workable string use: TextFile.ReadToString (http://www.indigorose.com/webhelp/suf70/Program_Reference/Actions/TextFile.ReadToString.htm)

Then to find where that certain string is use: String.Find (http://www.indigorose.com/webhelp/suf70/Program_Reference/Actions/String.Find.htm)

You should be able to replace the text and everything using the String actions.

Adam Kapilik

FSL
01-04-2007, 08:18 AM
Hi,

I am also trying to achieve the same outcome. Although my syntax, taken from above appears to be correct at the end of the installation the strings within the web.config file do not change.

This is my code,

config = File.Find("%AppFolder%", SessionVar.Expand("%AppFolder%\\Web.config"), false, false, nil, nil);
testtostring = TextFile.ReadToString(SessionVar.Expand("%AppFolder%\\Web.config"));
SQLServerName = String.Replace("@@SQLServer@@", "x", "%SQLServer%", false);
DBName = String.Replace("@@DatabaseName@@", "X", "%CGiXDatabase%", false);

The %SQLServer% and %CGiXDatabase% are parameters entered during the setup by the user via an edit fields screen.

Any help would be much appreciated as i am still getting to grips with this.

Thanks in advance.

FSL
01-04-2007, 09:20 AM
IN addition to the above this is the log file out put

[01/04/2007 15:21:25] Error Script: On Post Install, [1]: config = File.Find("%AppFolder%", SessionVar.Expand("%AppFolder%\\Web.config"), false, false, nil, nil); (1002)

Adam
01-04-2007, 03:14 PM
Any time that you use a %type% variable in script you need to use SessionVar.Expand() (http://www.indigorose.com/webhelp/suf70/Program_Reference/Actions/SessionVar.Expand.htm). I see in your code you have this action in some places but not in others.

Adam Kapilik

FSL
01-05-2007, 03:44 AM
HI Adam,

Thanks you so much for the reply. I have changed my code to the following

config = File.Find(SessionVar.Expand("%AppFolder%"), SessionVar.Expand("%AppFolder%\\Web.config"), false, false, nil, nil);
Application.GetLastError ()
testtostring = TextFile.ReadToString(SessionVar.Expand("%AppFolder%\\Web.config"));
Application.GetLastError ()
SQLServerName = String.Replace("@@SQLServer@@", "@@SQLServer@@", SessionVar.Expand("%SQLServer%"), false);
Application.GetLastError ()
DBName = String.Replace("@@DatabaseName@@", "@@DatabaseName@@", SessionVar.Expand("%CGiXDatabase%"), false);
Application.GetLastError ()

With the same results. I also added in the .GetLastError() function but again no errors were returned and the log file was empty. Could there be something wrong with the string that i am searching for within the file? These are the strings i am trying to search and change:-

<add key="sqlServer" value="@@SQLServer@@" />
<add key="sqlDatabase" value="@@DatabaseName@@" />

I have also attached a screenshot of where i have setup the session variables. These relate to an edit fields screen that asks for input during the installation.

FSL
01-06-2007, 07:46 AM
Adam,

Thanks for your help but i have now managed to achieve the outcome. Didnt realise there was an examples tab in the help section. This helped a lot and with some minor tweeking and a few debugging lines i have achieved it.

The code for reference by others is below.

Thanks again,
Stu


-- **************************** WEB.CONFIG **********************************************
-- Find the Web.Config
FindWebConfig = File.Find(SessionVar.Expand("%AppFolder%"), SessionVar.Expand("%AppFolder%\\Web.config"), false, false, nil, nil);

-- Read the contents of Web.Config into a string.
Webconfig = TextFile.ReadToString(SessionVar.Expand("%AppFolder%\\Web.config"));
Dialog.Message("config = ", Webconfig, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);

-- Check the error code.
error = Application.GetLastError();
-- If an error occurred, display the error message.
if (error ~= 0) then
Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
-- Replace every occurrence of the string "@@SQLServer@@" with the string entered in the setup for the SQL Server.
SQLServer_Name = String.Replace(Webconfig, "@@SQLServer@@", SessionVar.Expand("%SQLServer%"), false);

-- Write out the modified contents of Web.Config.
TextFile.WriteFromString("%AppFolder%\\Web.config", SQLServer_Name, false);

Webconfig2 = TextFile.ReadToString(SessionVar.Expand("%AppFolder%\\Web.config"));

-- Replace every occurrence of the string "@@SQLServer@@" with the string entered in the setup for the SQL Server.
Database_Name = String.Replace(Webconfig2, "@@DatabaseName@@", SessionVar.Expand("%CGiXDatabase%"), false);

-- Write out the modified contents of Web.Config.
TextFile.WriteFromString("%AppFolder%\\Web.config", Database_Name, false);

Webconfig3 = TextFile.ReadToString(SessionVar.Expand("%AppFolder%\\Web.config"));

Dialog.Message("Web.Config = ", Webconfig3, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);

-- Check the error code.
error = Application.GetLastError();
-- If an error occurred, display the error message.
if (error ~= 0) then
Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
end
end

mmedina2008
04-09-2008, 12:14 PM
any info how to auto config a webconfig file