protected void Button1_Click(object sender, EventArgs e)
    {        if(name.Text == "")
            {
                strPath = "C://Inetpub//wwwroot//" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls";
            }
        else
            {
                strPath = "C://Inetpub//wwwroot//" + name.Text + ".xls";
            }
            
        File1.PostedFile.SaveAs(strPath);
        string mystring = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = '" + strPath + "';Extended Properties=Excel 8.0";
        OleDbConnection cnnxls = new OleDbConnection(mystring);
        OleDbDataAdapter myDa = new OleDbDataAdapter("select * from [Sheet1$]", cnnxls);
        DataSet myDs = new DataSet();
        myDa.Fill(myDs);
        GridView2.DataSource = myDs.Tables[0];
        GridView2.DataBind();    }

解决方案 »

  1.   

    不知道你所谓的“相对地址”是什么意思?假设你是asp.net程序员,那么我猜你对于asp.net运行在哪里还是糊涂的。asp.net运行在服务器端,而不是客户端,因此没有什么“上传”概念,就是把文件保存在本地的、使用 Server.MapPath("~/xxxxxx")计算出来的具体路径下就行了。如果不是asp.net,那么你的客户端是什么呢?此时“相对地址”又是相对于什么而言的呢?
      

  2.   

    不知道你所谓的“相对地址”是什么意思?假设你是asp.net程序员,那么我猜你对于asp.net运行在哪里还是糊涂的。asp.net运行在服务器端,而不是客户端,因此没有什么“上传”概念,就是把文件保存在本地的、使用 Server.MapPath("~/xxxxxx")计算出来的具体路径下就行了。如果不是asp.net,那么你的客户端是什么呢?此时“相对地址”又是相对于什么而言的呢?
      

  3.   

    哦,我刚刚看到了File1.PostedFile这代码。其实asp.net服务器端编程的问题最发到asp.net论坛,这样比较方便直接判断问题归类。
      

  4.   

    我的意思是 这里是绝对路径,要改成相对的 "C://Inetpub//wwwroot//" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls"但是File1.PostedFile.SaveAs(strPath);只能用绝对路径 要怎么改?