Download Source Code: FileCode
Xaml :
<Window x:Class="FileHandling.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TextBox Height="23" HorizontalAlignment="Left" Margin="190,106,0,0" Name="filedatatxt" VerticalAlignment="Top" Width="120" />
<Button Content="Write Text" Height="23" HorizontalAlignment="Left" Margin="235,135,0,0" Name="writeBtn" VerticalAlignment="Top" Width="75" Click="writeBtn_Click" />
</Grid>
</Window>
Xaml :
<Window x:Class="FileHandling.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TextBox Height="23" HorizontalAlignment="Left" Margin="190,106,0,0" Name="filedatatxt" VerticalAlignment="Top" Width="120" />
<Button Content="Write Text" Height="23" HorizontalAlignment="Left" Margin="235,135,0,0" Name="writeBtn" VerticalAlignment="Top" Width="75" Click="writeBtn_Click" />
</Grid>
</Window>
C#:
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace FileHandling
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
// Reading from file which is located in debug folder
// Begins
string[] lines = File.ReadAllLines("Highscore.txt");
foreach (string tempLines in lines) {
MessageBox.Show(tempLines);
}
// Ends
}
private void writeBtn_Click(object sender, RoutedEventArgs e)
{
StreamWriter writeFile = new StreamWriter("Highscore.txt",true);
writeFile.WriteLine(filedatatxt.Text);
writeFile.Close();
}
}
}
No comments:
Post a Comment