473,396 Members | 1,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

passing data to a custom action

Hi!

Can anyone help me with translating a VB-code to C#?

I'm reading the walkthrough: Passing data to a custom action.
In part 4 were you create an installer class there is a example of VB-code.

I've tried to translate the code to c# but I have problem with a small part
of it ...
' Finds the right node and change it to the new value.
Dim Node As System.Xml.XmlNode
Dim FoundIt As Boolean = False
For Each Node In XmlDocument.Item("configuration").Item("appSetting s")
If Node.Name = "add" Then ' skip any comments
If Node.Attributes.GetNamedItem("key").Value = "ServerName" Then
Node.Attributes.GetNamedItem("value").Value = ProvidedName
FoundIt = True
End If
End If
Next Node
please help!

---------------
Best regards
- Hans -
---------------
(Have fun programming with ... C#)
Nov 17 '05 #1
3 2125

while waiting for help I've tried once more...

here is my example of the code.

any comments on the code appreciates.

public override void Install (System.Collections.IDictionary stateSaver)
{
//Get the parameter passed across in the CustomActionData
string strServerName = this.Context.Parameters["SNAME"];
string strDatabaseName = this.Context.Parameters["DBNAME"];

if(strServerName == "" || strDatabaseName == "")
throw new InstallException ("No arguments specified");

//Use reflection to find the location of the config file
Assembly Asm = Assembly.GetExecutingAssembly();
FileInfo fileInfo = new FileInfo(Asm.Location + ".config");

if (!fileInfo.Exists)
throw new InstallException ("Missing Config file");
//Load the config file into the XML DOM.
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load (fileInfo.FullName);

//Finds the right node and change it to the new value
XmlNodeList nodelist = xmlDocument.GetElementsByTagName ("appSettings");

bool foundServerName = false;
bool foundDataBaseName = false;

for (int i = 0; i < nodelist.Count; i++)
{
int y = 0;
XmlNode n = nodelist[i].FirstChild;
while (y < nodelist[i].ChildNodes.Count)
{
if(n.Name == "add")
{
if (n.Attributes["key"].Value == "SNAME")
{
n.Attributes["value"].Value = strServerName;
foundServerName = true;
}
else if (n.Attributes["key"].Value == "DBNAME")
{
n.Attributes["value"].Value = strDatabaseName;
foundDataBaseName = true;
}
}
n = n.NextSibling;
y++;
}
}

if(!foundDataBaseName || !foundServerName)
throw new InstallException ("config file did not contain a servername or a
databasename section");

//Write out the new config file.
xmlDocument.Save (fileInfo.FullName);
}
best regards

Hans
Nov 17 '05 #2
Hans,

It's always helpful if you explain exactly what the problem is. What error
you are getting on what line.

I'm guessing you're having problem with the Item properties. Usually those
become indexers in C#, so offhand:

foreach (XmlNode node in xmlDocument["configuration"]["appSettings"])

Double check the docs to make sure. You'll see that the Item property of
the XmlDocument has the notation, "In C#, this property is the indexer for
the XmlDocument class".

Also watch out for case sensitivity issues.

That's the best guess I can give you.

--Bob

"Hans [DiaGraphIT]" <ha********@sshf.no> wrote in message
news:1B**********************************@microsof t.com...
Hi!

Can anyone help me with translating a VB-code to C#?

I'm reading the walkthrough: Passing data to a custom action.
In part 4 were you create an installer class there is a example of
VB-code.

I've tried to translate the code to c# but I have problem with a small
part
of it ...
' Finds the right node and change it to the new value.
Dim Node As System.Xml.XmlNode
Dim FoundIt As Boolean = False
For Each Node In XmlDocument.Item("configuration").Item("appSetting s")
If Node.Name = "add" Then ' skip any comments
If Node.Attributes.GetNamedItem("key").Value = "ServerName" Then
Node.Attributes.GetNamedItem("value").Value = ProvidedName
FoundIt = True
End If
End If
Next Node
please help!

---------------
Best regards
- Hans -
---------------
(Have fun programming with ... C#)

Nov 17 '05 #3
Your not a bad guesser... :-)

thank you very much.

Hans

"Bob Grommes" wrote:
Hans,

It's always helpful if you explain exactly what the problem is. What error
you are getting on what line.

I'm guessing you're having problem with the Item properties. Usually those
become indexers in C#, so offhand:

foreach (XmlNode node in xmlDocument["configuration"]["appSettings"])

Double check the docs to make sure. You'll see that the Item property of
the XmlDocument has the notation, "In C#, this property is the indexer for
the XmlDocument class".

Also watch out for case sensitivity issues.

That's the best guess I can give you.

--Bob

"Hans [DiaGraphIT]" <ha********@sshf.no> wrote in message
news:1B**********************************@microsof t.com...
Hi!

Can anyone help me with translating a VB-code to C#?

I'm reading the walkthrough: Passing data to a custom action.
In part 4 were you create an installer class there is a example of
VB-code.

I've tried to translate the code to c# but I have problem with a small
part
of it ...
' Finds the right node and change it to the new value.
Dim Node As System.Xml.XmlNode
Dim FoundIt As Boolean = False
For Each Node In XmlDocument.Item("configuration").Item("appSetting s")
If Node.Name = "add" Then ' skip any comments
If Node.Attributes.GetNamedItem("key").Value = "ServerName" Then
Node.Attributes.GetNamedItem("value").Value = ProvidedName
FoundIt = True
End If
End If
Next Node
please help!

---------------
Best regards
- Hans -
---------------
(Have fun programming with ... C#)


Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains:...
1
by: Rob Oliver | last post by:
Hi, I've seen a walkthrough for passing data from a setup project to a custom action (an application) with an InstallClass. I am curious though--can the data also be intercepted by a custom...
11
by: Arsen Vladimirskiy | last post by:
Hello, If I have a few simple classes to represent Entities such as Customers and Orders. What is the proper way to pass information to the Data Access Layer? 1) Pass the actual ENTITY to...
3
by: Simon Harvey | last post by:
Hi, In my application I get lots of different sorts of information from databases. As such, a lot of information is stored in DataSets and DataTable objects. Up until now, I have been passing...
1
by: Hans [DiaGraphIT] | last post by:
Hi! I have problem with passing data to custom action. I don't know what wrong I'm doing. I'm trying to follow the steps in the walkthrough: "Passing Data to a Custom Action" ...
12
by: Noel | last post by:
Hello, I'm currently developing a web service that retrieves data from an employee table. I would like to send and retrieve a custom employee class to/from the webservice. I have currently coded...
3
by: MikeY | last post by:
Hi everyone, I'm having problems, or should I say still having problems with trying to pass data from my custom buttons in my custom controls to my main form listview box. Still scratching my...
2
by: | last post by:
I want to know how to make a clickable button or Command field on a GridView, and have the user's action a) fire a function and b) pass a data value from one of the GridView's columns to that...
13
by: Matt F | last post by:
I have a deployment project that I'm setting up. I need to perform a different custom action based on whether this is a first time install or an update. Does anyone have any idea if it's possible...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.