using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string FileName = string.Empty;
DataTable dtExcelData;
public Form1()
{
InitializeComponent();
}
private void bthChose_Click(object sender, EventArgs e)
{
OpenFileDialog opd = new OpenFileDialog();//实例化选择打开窗口对象
opd.Multiselect = false;//定义不允许多选
opd.Filter = "(*.*)|*.csv";//设置可以选择所有文件
if (opd.ShowDialog() == DialogResult.OK)
{
//写入自己的代码
txtFileName.Text = opd.FileName;
FileName = opd.FileName;
}
opd.Dispose();
}
private void button1_Click(object sender, EventArgs e)
{
string path = "";
string fname = "";
if (FileName.Length <= 0)
{
MessageBox.Show("请上传文件");
return;
}
else if (System.IO.Path.GetExtension(FileName) != ".csv")
{
MessageBox.Show("请上传csv格式文件");
return;
}
else
{
path = FileName.Substring(0, FileName.LastIndexOf("\\") + 1);
// fname = FileName.Substring(FileName.LastIndexOf("\\") + 1);
}
GetDate(path);
}
public void GetDate(string path)
{
try
{
Dat