liufeng

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
写:
StreamWriter sw ;
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("."+ 13);
            
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());
        }
posted on 2008-04-09 21:31  嚣张的沉默  阅读(261)  评论(0编辑  收藏  举报