日期:2014-05-18  浏览次数:20904 次

上传文件到相对路径
C# code

    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();

    }







------解决方案--------------------
结贴率太低...........................
------解决方案--------------------
不知道你所谓的“相对地址”是什么意思?

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

如果不是asp.net,那么你的客户端是什么呢?此时“相对地址”又是相对于什么而言的呢?
------解决方案--------------------
不知道你所谓的“相对地址”是什么意思?

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

如果不是asp.net,那么你的客户端是什么呢?此时“相对地址”又是相对于什么而言的呢?
------解决方案--------------------
哦,我刚刚看到了
C# code
File1.PostedFile