- 爱易网页
-
ASP.NET教程
- 点按钮传文件解决思路
日期:2014-05-18 浏览次数:20474 次
点按钮传文件
我想在ASP.NET通过按钮把从客户端的文本文件到入到数据库,我现在实现了自己指定的文件,怎么做那个弹出窗口让别人随意选择的文件
protected void btn_Import_Click(object sender, EventArgs e)
{
Regex reg = new Regex(@"^\d{2}-\d{1,2}-\d{1,2} \d{1,2}:\d{1,2}:\d{1,2}$", RegexOptions.None);
StreamReader sr = new StreamReader(@"D:\巡线任务.txt", System.Text.Encoding.Default);
do
{
string str = sr.ReadLine();
string[] strs = str.Split(',');
string s = strs[0];
string[] st = s.Split('`');
StringBuilder sb = new StringBuilder("");
if (reg.IsMatch(strs[strs.Length - 1]))
{
for (int i = 0; i < strs.Length; i++)
{
}
ListBox1.Items.Add(str);
//sb.Append("insert student values(')");
//sb.Append(strs[0]); sb.Append("','");
//sb.Append(strs[1]); sb.Append("','");
//sb.Append(strs[2]); sb.Append("','");
//sb.Append(strs[3]); sb.Append("','");
//sb.Append(strs[4]); sb.Append("','");
// //sb.Append(strs[5]); sb.Append("');");
sb.Append("insert into QX_XSJL(");
sb.Append("ID,XXR,BMMC,XLMC,ZLMC,GH,YWQX,XSSJ,SFSD,JINGDU,WEIDU");
sb.Append(")");
sb.Append(" values (");
sb.Append("'" + Global.strloginID + "',");
sb.Append("'" + Global.strloginname + "',");
sb.Append("'" + Global.strloginBM + "',");
sb.Append("'" + st[0] + "',");
sb.Append("'" + st[1] + "',");
sb.Append("'" + st[2] + "',");
sb.Append("'" + strs[6] + "',");
sb.Append("'" + strs[8] + "',");
sb.Append("'" + strs[7] + "',");
sb.Append("" + strs[3] + ",");
sb.Append("" + strs[4] + "");
sb.Append(")");
DAL.DbHelperSQL.ExecuteSql(sb.ToString());
}
} while (!sr.EndOfStream);
}
------解决方案--------------------
使用UploadFile控件。
------解决方案--------------------
//文件选择对话框
OpenFileDialog oOFD = new OpenFileDialog();
if (oOFD.ShowDialog() == DialogResult.OK)
{
//string [] fileList = oOFD.FileNames;//选择多个文件
textBox2.Text = oOFD.FileName;
}
//文件夹选择对话框
FolderBrowserDialog oFBD = new FolderBrowserDialog();
if (oFBD.ShowDialog() == DialogResult.OK)
{
textBox1.Text = oFBD.SelectedPath;
}