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.   

    B/S结构
    Server.MapPath("~/文件夹名/文件名")例如,项目Project1存在在D:\根目录下。即D:\Project1\
    那么String path = Server.MapPath("~/文件夹名/文件名.jpg");
    path的值就是 D:\Project1\文件夹名\文件名.jpg如果C/S结构
    application.方法  方法名称具体是什么忘了,你可以看下代码提示。
      

  2.   

    分无所谓,我不在乎。能帮助别人才是快乐的根源。
    不知道你需要加载什么文件。纯文本的用
    File f = File.Open("路径");就可以了(注意需要读写权限) 
    office的asp.net有相关的专门的类处理,度娘就行了。
      

  3.   

    Server.MapPath();
    不懂的自己上MSDN
      

  4.   

    就是上传的 .xls 文件,因为上传的时候文件名不一样,怎么判断是哪个呀?