http://msdn.microsoft.com/ru-ru/library/ybsdta26(v=vs.110).aspx
http://www.dotnetperls.com/openfiledialog
http://www.dotnetperls.com/split
http://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b
private void button1_Click(object sender, EventArgs e) { int size = -1; DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog. if (result == DialogResult.OK) // Test result. { string file = openFileDialog1.FileName; try { string text = File.ReadAllText(file); size = text.Length; } catch (IOException) { } } Console.WriteLine(size); // <-- Shows file size in debugging mode. Console.WriteLine(result); // <-- For debugging use. }
http://stackoverflow.com/questions/7387085/how-to-read-an-entire-file-to-a-string-using-c-sharp
string readContents;
using (StreamReader streamReader = new StreamReader(path, Encoding.UTF8))
{
readContents = streamReader.ReadToEnd();
}
public partial class Form1 : Form
{
//private PortfolioViewForm _pvForm ;
private PortfolioManagerForm2 _pmForm;
private readonly PortfolioManager _pm;
public Form1()
{
InitializeComponent();
_pm = PortfolioManager.Instance;
}
private void Form1_Load(object sender, EventArgs e)
{
_pmForm = new PortfolioManagerForm2(_pm);
_pmForm.Show();
}
private void btnSelectFile_Click(object sender, EventArgs e)
{
int size = -1;
DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog.
if (result == DialogResult.OK) // Test result.
{
string file = openFileDialog1.FileName;
try
{
string text = File.ReadAllText(file);
size = text.Length;
txtFileSelected.Text = file;
//var sr = new StringReader(text);
//var lst = new List<string>();
//string str = string.Empty;
//while ((str = sr.ReadLine()) != null)
//{
// lst.Add(str);
//}
//listFileLines.DataSource = lst;
string readContents;
var lst = new List<string>();
using (var streamReader = new StreamReader(file, Encoding.UTF8))
{
//readContents = streamReader.ReadToEnd();
while (!streamReader.EndOfStream)
{
//lst.Add(streamReader.ReadLine());
var s = streamReader.ReadLine();
if (s != null) listFileLines.Items.Add(s);
}
}
//listFileLines.DataSource = lst;
}
catch (IOException)
{
}
}
}
}
Комментариев нет:
Отправить комментарий