Wenn dies Ihr erster Besuch hier ist,
lesen Sie bitte zuerst die Hilfe - Häufig gestellte Fragen
durch. Sie müssen sich vermutlich registrieren,
bevor Sie Beiträge verfassen können. Klicken Sie oben auf 'Registrieren', um den Registrierungsprozess zu
starten. Sie können auch jetzt schon Beiträge lesen. Suchen Sie sich einfach das Forum aus, das Sie am meisten
interessiert.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Test1" value="This is the value of Test1" />
<add key="Test2" value="This is the value of Test2" />
</appSettings>
</configuration>
XML in Textbox Lesen
Dim config As System.Configuration.ConfigurationSettings
Dim key As String
With Me.TextBox1
For Each key In config.AppSettings.AllKeys
.AppendText(config.AppSettings(key) & vbCrLf)
Next
End With
Ansonsten mal was in C#
Sollte vielleicht als einzelne Classenbibliothek (*.dll) bei VB-Net gespeichert werden.
Gruß Mary Leipzig
-----------------------------------------------
//
// Author: Uri02 [email protected]
// U can use it but, please don't remove the author
// If you have any question or suggest,ask me !
//
//
using System;
using System.Diagnostics;
using System.Collections;
using System.Collections.Specialized;
using System.IO;
namespace Utils.Uri.Psp.Program3
{
public class IniFileManager
{
// Thw IniFileManager class is to manipulate Standart Ini Files
//
// * Sections & Keys can't have spaces at the begin or at the end
// * Sections & Keys are Case sensitive
// * Constructors
// - public IniFileManager(string iniFileName)
// - public IniFileManager()
// * Properties
// - IniFileName (set/get)
// * Methods:
// - EraseSection
// - EraseSectionKey
// - ExistsSection
// - ExistsSectionKey
// - FlushToDisk
// - ReadValue
// - WriteValue
// - GetAllSectionNames (TODO)
// - GetAllKeysBySection (TODO)
// - GetAllSectionKeys (TODO)
//Private variables
private string myIniFileName="";
private bool myFileReaded = false;
private SortedList myFileLines = new SortedList(); // This collection contains all the lines by order
private SortedList mySectionKeysLines = new SortedList(); // SortedList to find the Sections & Keys quickly, the key is [Section]+Key and the value is the number of the line
private long MaxFileLines =0;
private long InsertedKeys =0;
enum iniLineType {empty,comment,section,keyValue};
//Constructor
public IniFileManager(string iniFileName)
{
Debug.Assert ( iniFileName != null && iniFileName != "");
myIniFileName = iniFileName;
myFileReaded = ReadIniFile();
}
public IniFileManager()
{
myFileReaded =false;
}
//Properties
public string IniFileName
{
get { return myIniFileName; }
set
{
myFileReaded = false;
myIniFileName = value;
}
}
//Private Methods
private string BuildSectionKeyToHKey(string section,string key) { //HKey denotes HashtableKey
//To Build Section+Key to a sortedlist Key ([Section1]Key1)
Debug.Assert(section != null && section!= "");
Debug.Assert(key !=null && key!="" && key.IndexOf("=")<0);//Char "=" not permit in key Name
return (BuildSectionToHKey(section) + key.Trim());
}
private string BuildSectionToHKey(string section) { //HKey denotes HashtableKey
//To Build section to a sortedlist Key ([Section1])
Debug.Assert(section != null && section!= "");
return ("["+ section.Trim()+ "]");
}
private string BuildLineToHKey(string lineCount, string extension)
{
//To Build the valid index to be sorted by the SortList
return( lineCount.PadLeft(10,"0".ToCharArray()[0]) + extension);
}
private bool ReadIniFile()
{
//It Fills the Table with the Sections and the Sections+Keys
//If any error ocurs, it throws an exception "Error reading" and the "real" exception like a InnerException
if (myFileReaded==true) return (true);
if (!File.Exists(myIniFileName))
{
FileStream myNewFile = File.Create (myIniFileName);
myNewFile.Close();
}
string line = "";
long lineCount =0;
myFileLines = new SortedList();
mySectionKeysLines = new SortedList();
string currentSection="[Default]"; // If it find Key without Section at the begining of the file
using (StreamReader readFileStream = new StreamReader(myIniFileName) )
{
try
{
while (readFileStream.Peek() > -1) //Returns -1 when it finds the end of file
{
line = readFileStream.ReadLine().Trim(); //Removes all spaces
lineCount ++ ;
if (this.GetIniLineType(line)== (int) iniLineType.section)
{
currentSection = line;
mySectionKeys
Comment