写:
读:
读Execl
StreamWriter sw ;
sw = File.CreateText(@"e:\aa.txt");
sw.WriteLine(TextBox2.Text);
sw.Close();
sw = File.CreateText(@"e:\aa.txt");
sw.WriteLine(TextBox2.Text);
sw.Close();
读:
if (FileUpload1.PostedFile.FileName != "")
{
FilePath = FileUpload1.PostedFile.FileName;
fileExtName = FilePath.Substring(FilePath.LastIndexOf(".") + 1, 3);
if (fileExtName.Equals("txt"))
{
StreamReader fileStream = new StreamReader(this.FileUpload1.PostedFile.InputStream, Encoding.Default);
string filestr = fileStream.ReadToEnd();
fileStream.Close();
TextBox2.Text = filestr;
}
else
{
Response.Write("错了");
}
}
{
FilePath = FileUpload1.PostedFile.FileName;
fileExtName = FilePath.Substring(FilePath.LastIndexOf(".") + 1, 3);
if (fileExtName.Equals("txt"))
{
StreamReader fileStream = new StreamReader(this.FileUpload1.PostedFile.InputStream, Encoding.Default);
string filestr = fileStream.ReadToEnd();
fileStream.Close();
TextBox2.Text = filestr;
}
else
{
Response.Write("错了");
}
}
读Execl
string strFileName = FileUpload1.FileName;
string imgpath = Server.MapPath("~/inputFile/");
FileUpload1.SaveAs(imgpath + strFileName);
try
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + imgpath + "\\" + strFileName + ";" + "Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
OleDbDataAdapter oda = new OleDbDataAdapter("select * from [Sheet1$]", strConn); //oda.Fill(ds);
oda.Fill(ds,"aa");
GridView1.DataSource = ds.Tables["aa"];
GridView1.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
string imgpath = Server.MapPath("~/inputFile/");
FileUpload1.SaveAs(imgpath + strFileName);
try
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + imgpath + "\\" + strFileName + ";" + "Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
OleDbDataAdapter oda = new OleDbDataAdapter("select * from [Sheet1$]", strConn); //oda.Fill(ds);
oda.Fill(ds,"aa");
GridView1.DataSource = ds.Tables["aa"];
GridView1.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}