What is the best method to achieve this (I am relatively new to
vb.net)? Should I use an ini file or the registry? Is there another
option available in vb.net that is the preferred way? This
application will reside on our network and more than one user could
possibly run it so I don't think the local registry is the answer.
Basically I just want to remember the options the last user chose on
the form and then use those previously used settings the next time the
program is run.
Aug 19 '08
18 1452
On Aug 19, 2:17 pm, "Bill McCarthy" <B...@localhost .comwrote:
Hi Mel,
"Mel" <MLights...@gma il.comwrote in message
news:1c******** *************** ***********@e53 g2000hsa.google groups.com...
Anyone have a good link to an article that explains to how to read/
write to an XML file from VB.net? I only need to remember 3 darn
settings...
Are the settings for all users or per user ? If the later then use
My.SEttigns and the settings designer.
If for all users, and you are using VB 2008, use XDocument, e.g:
To read:
Dim doc As XDocument = XDocument.Load( "settings.x ml")
Dim setting1 As String = doc...<setting1 >.Value
Dim setting2 As String = doc...<setting2 >.Value
Dim setting3 As String = doc...<setting3 >.Value
To Write:
Dim doc = <?xml version="1.0"?>
<settings>
<setting1>top secret key</setting1>
<setting2>my credit card number</setting2>
<setting3>my social security number</setting3>
</settings>
doc.Save("setti ngs.xml")
Or using placeholders:
Dim doc = <?xml version="1.0"?>
<settings>
<setting1><%= setting1 %></setting1>
<setting2><%= setting2 %></setting2>
<setting3><%= setting3 %></setting3>
</settings>
Okay so I was able to load the XML file. How exactly do I read a node
value? I tried all sort of scenarios of doc...<setting1 >.value like
you instructed but I just can't get it to work. Can you post an exact
example (without ellipse characters)?
'this is my tiny xml file
<?xml version="1.0" encoding="utf-8" ?>
<xmldata>
<IncreaseOrDecr ease>Increase</IncreaseOrDecre ase>
<Percent>50</Percent>
<DateLastUpdate d>8/19/2008 8:00:00 AM</DateLastUpdated >
</xmldata>
'end of my tiny xml file
'my code in form load
Dim document As XmlDocument = New XmlDocument()
document.Load(S ystem.AppDomain .CurrentDomain. BaseDirectory &
"\settings.xml" ) 'this works
'how do I read Percent, IncreaseOrDecre ase and DateLastUpdated
from the xml file?
document...
'end of my code in form load
Hi Mel,
"Mel" <ML********@gma il.comwrote in message
news:45******** *************** ***********@k30 g2000hse.google groups.com...
On Aug 19, 2:17 pm, "Bill McCarthy" <B...@localhost .comwrote:
>Hi Mel,
"Mel" <MLights...@gma il.comwrote in message
news:1c******* *************** ************@e5 3g2000hsa.googl egroups.com...
Anyone have a good link to an article that explains to how to read/
write to an XML file from VB.net? I only need to remember 3 darn
settings...
Are the settings for all users or per user ? If the later then use My.SEttigns and the settings designer.
If for all users, and you are using VB 2008, use XDocument, e.g:
To read:
Dim doc As XDocument = XDocument.Load( "settings.x ml") Dim setting1 As String = doc...<setting1 >.Value Dim setting2 As String = doc...<setting2 >.Value Dim setting3 As String = doc...<setting3 >.Value
To Write:
Dim doc = <?xml version="1.0"?> <settings> <setting1>top secret key</setting1> <setting2>my credit card number</setting2> <setting3>my social security number</setting3> </settings>
doc.Save("setti ngs.xml")
Or using placeholders:
Dim doc = <?xml version="1.0"?> <settings> <setting1><%= setting1 %></setting1> <setting2><%= setting2 %></setting2> <setting3><%= setting3 %></setting3> </settings>
Okay so I was able to load the XML file. How exactly do I read a node
value? I tried all sort of scenarios of doc...<setting1 >.value like
you instructed but I just can't get it to work. Can you post an exact
example (without ellipse characters)?
'this is my tiny xml file
<?xml version="1.0" encoding="utf-8" ?>
<xmldata>
<IncreaseOrDecr ease>Increase</IncreaseOrDecre ase>
<Percent>50</Percent>
<DateLastUpdate d>8/19/2008 8:00:00 AM</DateLastUpdated >
</xmldata>
'end of my tiny xml file
'my code in form load
Dim document As XmlDocument = New XmlDocument()
document.Load(S ystem.AppDomain .CurrentDomain. BaseDirectory &
"\settings.xml" ) 'this works
'how do I read Percent, IncreaseOrDecre ase and DateLastUpdated
from the xml file?
document...
'end of my code in form load
Are you using VB 2008 ? If so try cutting and pasting my code. The ... is
part of 2008's syntax with XDocument. Note that is XDocument, not
XMLDocument.
On Aug 19, 8:05 pm, "Bill McCarthy" <B...@localhost .comwrote:
Hi Mel,
"Mel" <MLights...@gma il.comwrote in message
news:45******** *************** ***********@k30 g2000hse.google groups.com...
On Aug 19, 2:17 pm, "Bill McCarthy" <B...@localhost .comwrote:
Hi Mel,
"Mel" <MLights...@gma il.comwrote in message
>news:1c******* *************** ************@e5 3g2000hsa.googl egroups.com...
Anyone have a good link to an article that explains to how to read/
write to an XML file from VB.net? I only need to remember 3 darn
settings...
Are the settings for all users or per user ? If the later then use
My.SEttigns and the settings designer.
If for all users, and you are using VB 2008, use XDocument, e.g:
To read:
Dim doc As XDocument = XDocument.Load( "settings.x ml")
Dim setting1 As String = doc...<setting1 >.Value
Dim setting2 As String = doc...<setting2 >.Value
Dim setting3 As String = doc...<setting3 >.Value
To Write:
Dim doc = <?xml version="1.0"?>
<settings>
<setting1>top secret key</setting1>
<setting2>my credit card number</setting2>
<setting3>my social security number</setting3>
</settings>
doc.Save("setti ngs.xml")
Or using placeholders:
Dim doc = <?xml version="1.0"?>
<settings>
<setting1><%= setting1 %></setting1>
<setting2><%= setting2 %></setting2>
<setting3><%= setting3 %></setting3>
</settings>
Okay so I was able to load the XML file. How exactly do I read a node
value? I tried all sort of scenarios of doc...<setting1 >.value like
you instructed but I just can't get it to work. Can you post an exact
example (without ellipse characters)?
'this is my tiny xml file
<?xml version="1.0" encoding="utf-8" ?>
<xmldata>
<IncreaseOrDecr ease>Increase</IncreaseOrDecre ase>
<Percent>50</Percent>
<DateLastUpdate d>8/19/2008 8:00:00 AM</DateLastUpdated >
</xmldata>
'end of my tiny xml file
'my code in form load
Dim document As XmlDocument = New XmlDocument()
document.Load(S ystem.AppDomain .CurrentDomain. BaseDirectory &
"\settings.xml" ) 'this works
'how do I read Percent, IncreaseOrDecre ase and DateLastUpdated
from the xml file?
document...
'end of my code in form load
Are you using VB 2008 ? If so try cutting and pasting my code. The ... is
part of 2008's syntax with XDocument. Note that is XDocument, not
XMLDocument.
I am using:
Visual Basic 2005, Visual Studio 2005 Version 8.0.50727.42, WinXP SP2,
On Aug 20, 7:43 am, Mel <MLights...@gma il.comwrote:
On Aug 19, 8:05 pm, "Bill McCarthy" <B...@localhost .comwrote:
Hi Mel,
"Mel" <MLights...@gma il.comwrote in message
news:45******** *************** ***********@k30 g2000hse.google groups.com...
On Aug 19, 2:17 pm, "Bill McCarthy" <B...@localhost .comwrote:
>Hi Mel,
>"Mel" <MLights...@gma il.comwrote in message
>>news:1c****** *************** *************@e 53g2000hsa.goog legroups.com...
Anyone have a good link to an article that explains to how to read/
write to an XML file from VB.net? I only need to remember 3 darn
settings...
>Are the settings for all users or per user ? If the later then use
>My.SEttigns and the settings designer.
>If for all users, and you are using VB 2008, use XDocument, e.g:
>To read:
>Dim doc As XDocument = XDocument.Load( "settings.x ml")
> Dim setting1 As String = doc...<setting1 >.Value
> Dim setting2 As String = doc...<setting2 >.Value
> Dim setting3 As String = doc...<setting3 >.Value
>To Write:
> Dim doc = <?xml version="1.0"?>
> <settings>
> <setting1>top secret key</setting1>
> <setting2>my credit card number</setting2>
> <setting3>my social security number</setting3>
> </settings>
> doc.Save("setti ngs.xml")
>Or using placeholders:
> Dim doc = <?xml version="1.0"?>
> <settings>
> <setting1><%= setting1 %></setting1>
> <setting2><%= setting2 %></setting2>
> <setting3><%= setting3 %></setting3>
> </settings>
Okay so I was able to load the XML file. How exactly do I read a node
value? I tried all sort of scenarios of doc...<setting1 >.value like
you instructed but I just can't get it to work. Can you post an exact
example (without ellipse characters)?
'this is my tiny xml file
<?xml version="1.0" encoding="utf-8" ?>
<xmldata>
<IncreaseOrDecr ease>Increase</IncreaseOrDecre ase>
<Percent>50</Percent>
<DateLastUpdate d>8/19/2008 8:00:00 AM</DateLastUpdated >
</xmldata>
'end of my tiny xml file
'my code in form load
Dim document As XmlDocument = New XmlDocument()
document.Load(S ystem.AppDomain .CurrentDomain. BaseDirectory &
"\settings.xml" ) 'this works
'how do I read Percent, IncreaseOrDecre ase and DateLastUpdated
from the xml file?
document...
'end of my code in form load
Are you using VB 2008 ? If so try cutting and pasting my code. The ... is
part of 2008's syntax with XDocument. Note that is XDocument, not
XMLDocument.
I am using:
Visual Basic 2005, Visual Studio 2005 Version 8.0.50727.42, WinXP SP2,
I finally got it to work. I don't know if this is the best way to do
it but at any rate it works. I put the code I ended up with below.
Now all I need to do is figure out how to write the settings to the
xml file when they close the form.
Private Sub frmFreightCostA djustment_Load( ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
'RETIEVE LAST SETTINGS FROM THE XML FILE. DEFAULT THE FORM TO
THE LAST SETTINGS USED.
Using reader As System.Xml.XmlR eader =
System.Xml.XmlR eader.Create("c :\w\settings.xm l")
reader.ReadToFo llowing("xmldat a")
reader.ReadToFo llowing("Percen t")
nudPercent.Valu e = reader.ReadElem entContentAsStr ing()
'set numeric up down control to the last percent used
reader.ReadToFo llowing("Increa seORDecrease")
If UCase(Trim(read er.ReadElementC ontentAsString( ))) =
"INCREASE" Then 'set increase or decrease radio button
radInc.Checked = True
Else
radDec.Checked = True
End If
reader.ReadToFo llowing("DateLa stUpdated")
lblLastUpd.Text = reader.ReadElem entContentAsStr ing()
'set the last date updated label to the last date the program was run
reader.Close()
End Using
End Sub
'here is what my settings.xml file looks like
<?xml version="1.0" encoding="utf-8" ?>
<xmldata>
<Percent>50</Percent>
<IncreaseORDecr ease>INCREASE</IncreaseORDecre ase>
<DateLastUpdate d>8/18/2008 8:00:00 AM</DateLastUpdated >
</xmldata>
Mel wrote:
I finally got it to work. I don't know if this is the best way to do
it but at any rate it works. I put the code I ended up with below.
Now all I need to do is figure out how to write the settings to the
xml file when they close the form.
Private Sub frmFreightCostA djustment_Load( ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
'RETIEVE LAST SETTINGS FROM THE XML FILE. DEFAULT THE FORM TO
THE LAST SETTINGS USED.
Using reader As System.Xml.XmlR eader =
System.Xml.XmlR eader.Create("c :\w\settings.xm l")
You might want to store it somewhere that all users have access to, bearing
in mind Vista security.
From shlobj.h in the Windows Server 2003 SDK, regarding special folder
enumeration:
#define CSIDL_COMMON_AP PDATA 0x0023 // All
Users\Applicati on Data
'here is what my settings.xml file looks like
<?xml version="1.0" encoding="utf-8" ?>
<xmldata>
<Percent>50</Percent>
<IncreaseORDecr ease>INCREASE</IncreaseORDecre ase>
<DateLastUpdate d>8/18/2008 8:00:00 AM</DateLastUpdated >
</xmldata>
You appear to be in a country where there are at least 18 months in a
year... perhaps storing the date/time in a format like yyyyMMddThhmmss would
be a good idea.
HTH
Andrew
On Aug 20, 9:50 am, "Andrew Morton" <a...@in-press.co.uk.inv alid>
wrote:
Mel wrote:
I finally got it to work. I don't know if this is the best way to do
it but at any rate it works. I put the code I ended up with below.
Now all I need to do is figure out how to write the settings to the
xml file when they close the form.
Private Sub frmFreightCostA djustment_Load( ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
'RETIEVE LAST SETTINGS FROM THE XML FILE. DEFAULT THE FORM TO
THE LAST SETTINGS USED.
Using reader As System.Xml.XmlR eader =
System.Xml.XmlR eader.Create("c :\w\settings.xm l")
You might want to store it somewhere that all users have access to, bearing
in mind Vista security.
From shlobj.h in the Windows Server 2003 SDK, regarding special folder
enumeration:
#define CSIDL_COMMON_AP PDATA 0x0023 // All
Users\Applicati on Data
'here is what my settings.xml file looks like
<?xml version="1.0" encoding="utf-8" ?>
<xmldata>
<Percent>50</Percent>
<IncreaseORDecr ease>INCREASE</IncreaseORDecre ase>
<DateLastUpdate d>8/18/2008 8:00:00 AM</DateLastUpdated >
</xmldata>
You appear to be in a country where there are at least 18 months in a
year... perhaps storing the date/time in a format like yyyyMMddThhmmss would
be a good idea.
HTH
Andrew
Yeah, "c:\w" is my test directory. I was hoping to use
System.AppDomai n.CurrentDomain .BaseDirectory & "\system.xm l".
I am just using the vb.net Now property.
On Aug 20, 10:17 am, Mel <MLights...@gma il.comwrote:
On Aug 20, 9:50 am, "Andrew Morton" <a...@in-press.co.uk.inv alid>
wrote:
Mel wrote:
I finally got it to work. I don't know if this is the best way to do
it but at any rate it works. I put the code I ended up with below.
Now all I need to do is figure out how to write the settings to the
xml file when they close the form.
Private Sub frmFreightCostA djustment_Load( ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
'RETIEVE LAST SETTINGS FROM THE XML FILE. DEFAULT THE FORM TO
THE LAST SETTINGS USED.
Using reader As System.Xml.XmlR eader =
System.Xml.XmlR eader.Create("c :\w\settings.xm l")
You might want to store it somewhere that all users have access to, bearing
in mind Vista security.
From shlobj.h in the Windows Server 2003 SDK, regarding special folder
enumeration:
#define CSIDL_COMMON_AP PDATA 0x0023 // All
Users\Applicati on Data
'here is what my settings.xml file looks like
<?xml version="1.0" encoding="utf-8" ?>
<xmldata>
<Percent>50</Percent>
<IncreaseORDecr ease>INCREASE</IncreaseORDecre ase>
<DateLastUpdate d>8/18/2008 8:00:00 AM</DateLastUpdated >
</xmldata>
You appear to be in a country where there are at least 18 months in a
year... perhaps storing the date/time in a format like yyyyMMddThhmmss would
be a good idea.
HTH
Andrew
Yeah, "c:\w" is my test directory. I was hoping to use
System.AppDomai n.CurrentDomain .BaseDirectory & "\system.xm l".
I am just using the vb.net Now property.
Anyone know how do I output carriage returns when I write my XML
file? My code below creates the xml file but all of the data is on
one big long line.
Dim writer As New XmlTextWriter(" C:\w\settings-
newfile.xml", Nothing)
writer.WriteSta rtDocument()
writer.WriteSta rtElement("xmld ata", "")
writer.WriteSta rtElement("Perc ent", "")
writer.WriteStr ing(nudPercent. Value) 'output numeric up
down control percent value
writer.WriteEnd Element() 'end Percent
writer.WriteSta rtElement("Incr easeORDecrease" , "")
If strIncDec = "increase" Then
writer.WriteStr ing("INCREASE") 'increase radio
button was chosen
Else
writer.WriteStr ing("DECREASE") 'decrease radio button
was chosen
End If
writer.WriteEnd Element() 'end IncreaseORDecre ase
writer.WriteSta rtElement("Date LastUpdated", "")
writer.WriteStr ing(Now) 'output the date/time the program
was run
writer.WriteEnd Element() 'end DateLastUpdated
writer.WriteEnd Element() 'end xmldata
writer.WriteEnd Document()
writer.Close()
On Wed, 20 Aug 2008 08:41:00 -0700 (PDT), Mel <ML********@gma il.com>
wrote:
>Anyone know how do I output carriage returns when I write my XML file? My code below creates the xml file but all of the data is on one big long line.
Did you look at the code I sent you?
--
Dennis
On Aug 20, 11:30 am, Dennis <nob...@nowhere .invalidwrote:
On Wed, 20 Aug 2008 08:41:00 -0700 (PDT), Mel <MLights...@gma il.com>
wrote:
Anyone know how do I output carriage returns when I write my XML
file? My code below creates the xml file but all of the data is on
one big long line.
Did you look at the code I sent you?
--
Dennis
Yep, I've got it! It's working like a charm now. Thank you :) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: McGeeky |
last post by:
Is there a way to get a user control to remember its state across pages? I
have a standard page layout I use with a header and footer as user controls.
Each page uses the same layout by means of copy paste (I hear this will
improve in ASP.Net 2 via master pages).
When I navigate from one page to the next the header and footer user
controls lose their state because they are effectively different instances
of the user control.
Is there...
|
by: theWizard1 |
last post by:
Using Visual Studio.Net 2005, Asp.Net 2.0, and trying to use technique shown
in the Programming Asp.Net 3rd Edition by O'Reily, page 257.
On the first page, this would become the previous page, I have 2 dropdowns.
According to their technique, I should create a public property on my
previous page for these 2 dropdowns, and then I would would be able to get
their settings on the target aspx page.
I have added the 2 properties on the...
|
by: WT |
last post by:
Hello,
I have been publishing my web site many times to the remote where resides my
final web site.
Everything was ok, but to-day, without any configuration change, vs doesn't
copy final files to the remote site.
It finish with a message of publish sucess but no files nor folders on the
remote disk ?
I have checked rights on this folder, everyone have modify.
|
by: Paul Cheetham |
last post by:
Hi,
I am developing an application that needs to store some machine-specific
settings. The application is going to be published on the network in
order to keep the clients on the latest version.
Because of this, I am unable to store these settings in the App.Config
file, as this gets updated every time the application does, and there
doesn't appear to be a way of preventing this.
Most of my application settings are kept in the...
|
by: Chris Dunaway |
last post by:
I have an .exe console project and a class library project as part of a
solution. The .exe has an App.config file and I have used the Settings
page to add some Application level settings.
When I try to retrieve a setting using this code:
//Method 1
string s = ConfigurationManager.AppSettings;
| |
by: Manikandan |
last post by:
Hi,
I'm creating a setup project for my c# application(Contains solution,
c# project, setup project).
In setup project properties, i set removepreviousversion
property=true.
Created the installer and tested, installed successfully.
If i install again means it's asking a dialogue with an option to
repair, remove.
Now I make some changes in my c# codings and build the installer for
the same appliaction.
|
by: cj |
last post by:
I was googling for a way to have my single form application start in the
same location on the screen it was in when it was closed. I found this
very short article:
http://blogs.techrepublic.com.com/programming-and-development/?p=540
I can create the my.settings object as specified but I can't set the
form1's location to mainformlocation in form1's properties. It takes an
X and Y location.
|
by: Mel |
last post by:
What is the best method to achieve this (I am relatively new to
vb.net)? Should I use an ini file or the registry? Is there another
option available in vb.net that is the preferred way? This vb.net
application will reside on our network and more than one user could
possibly run it so I don't think the local registry is the answer.
Basically I just want to remember the options the last user chose on
the form and then use those previously...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |