MainWindow.xaml.csの全コード
using System;
using System.Windows;
using System.Windows.Forms;
using System.IO;
namespace WpfFileTestB
{
public partial class MainWindow : Window
{
String[,] RCData = new String[50, 20];
public MainWindow()
{
InitializeComponent();
}
private void Button1_Click(object sender, RoutedEventArgs e)
{
int i, j;
if (myControl.OpenFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
using (Microsoft.VisualBasic.FileIO.TextFieldParser MyReader = new Microsoft.VisualBasic.FileIO.TextFieldParser(myControl.OpenFileDialog1.FileName))
{
MyReader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited;
MyReader.SetDelimiters("\t");
String[] currentRow;
i = 0;
while (MyReader.EndOfData != true)
{
try
{
currentRow = MyReader.ReadFields();
j = 0;
foreach (String currentField in currentRow)
{
RCData[i, j] = currentField;
if (j < 9) { j = j + 1; }
}
}
catch (InvalidCastException ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
if (i < 49) { i = i + 1; }
}
}
String OutText = "";
for (i = 0; i < 49; i++)
{
for (j = 0; j < 9; j++)
{
OutText = OutText + RCData[i, j] + " , ";
}
OutText = OutText + "\r\n";
}
if (myControl.SaveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
using (StreamWriter outfile = new StreamWriter(myControl.SaveFileDialog1.FileName))
{
outfile.Write(OutText);
}
}
}
}
}
}