<Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" xmlns:self="clr-namespace:WpfFileTest" Title="MainWindow" Height="220" Width="282"> <Grid> <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="23,11,0,0" Name="Button1" VerticalAlignment="Top" Width="75" /> <WindowsFormsHost Visibility="Hidden"> <self:UserControl1 x:Name="myControl"/> </WindowsFormsHost> </Grid> </Window>
Class MainWindow Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If myControl.OpenFileDialog1.ShowDialog() = Forms.DialogResult.OK Then Dim sr As System.IO.StreamReader = My.Computer.FileSystem.OpenTextFileReader(myControl.OpenFileDialog1.FileName) Dim FirstLine As String = sr.ReadLine() & vbCrLf & sr.ReadLine() MsgBox(FirstLine) Dim reader As String = My.Computer.FileSystem.ReadAllText(myControl.OpenFileDialog1.FileName) If myControl.SaveFileDialog1.ShowDialog() = Forms.DialogResult.OK Then My.Computer.FileSystem.WriteAllText(myControl.SaveFileDialog1.FileName, reader, append:=False) End If End If End Sub End Class