hi,
If File.Exists("F:\User.txt") Then
'Load user accounts
Dim sr As StreamReader = New StreamReader("F:\user.txt")
Dim sInput As String = ""
Dim ThisRow() As String
Dim sData() As String
Dim i As Integer
'//=Read all Data into sInput
Do While sr.Peek >= 0
sInput = sInput & sr.ReadLine & ControlChars.CrLf
Loop
ThisRow = Split(sInput, vbCrLf)
For i = 0 To UBound(ThisRow) - 1
sData = Split(ThisRow(i), ",")
Dim lsvi As New ListViewItem(sData, 2)
ListView1.Items.Add(lsvi)
Next
ListView1.Sort()
sr.Close()
End If
i tried with this it is not working at Split
if
(File.Exists("F:\\User.txt")){
//Load user accounts StreamReader sr = new StreamReader("F:\\user.txt"); string sInput = ""; string[] ThisRow = null; string[] sData = null; int i = 0; ////=Read all Data into sInput if (sr.Peek() >= 0){
sInput = sInput + sr.ReadLine() +
"\r\n";}
ThisRow = sInput.Split(
"\r\n",ThisRow); int temp = ThisRow.GetUpperBound(1); for (i = 0; i <= temp - 1; i++){
sData = Strings.Split(ThisRow(i),
","); ListViewItem lsvi = new ListViewItem(sData, 2);listView1.Items.Add(lsvi);
}
listView1.Sort();
sr.Close();
}
Suchit KhannaPosted May 25, 2009, 6:01 AM
This is a rough code you could use to build upon your requirement, I have used a WPF form as example:
The XAML code goes like this:
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
And the Code behind goes like this:
public partial class Window1 : Window
{
private StreamReader reader = null;
private string myPath = null;
private StreamWriter writer = null;
private FileStream file = null;
public Window1()
{
InitializeComponent();
ReadFromFile();
}
void ReadFromFile()
{
myPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
try
{
reader = new StreamReader(myPath + "\\Test.txt");
while (reader.Peek() > 0)
{
string sInput = reader.ReadLine();
lstStoreInFile.Items.Add(sInput);
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
finally
{
reader.Close();
reader.Dispose();
}
}
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
try
{
file = File.Open(myPath + "\\Test.txt", FileMode.Append, FileAccess.Write);
writer = new StreamWriter(file);
writer.BaseStream.Seek(0, SeekOrigin.End);
writer.WriteLine(txtNewItem.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
writer.Flush();
writer.Close();
writer.Dispose();
file.Close();
file.Dispose();
}
lstStoreInFile.Items.Clear();
ReadFromFile();
}
}
saradaPosted May 23, 2009, 1:51 AM
Suchit KhannaPosted May 23, 2009, 1:46 AM