protected void ADMIN_FILEUPLOAD_BT_Click(object sender, EventArgs e)
    {
            String savePath = "C:\\Documents and Settings\\Dang\\My Documents\\Visual Studio 2008\\WebSites\\新闻发布系统\\Upload\\";
            bool boolean = false;
            string FileName="a";
            string FilePath="b";
            if (ADMIN_FileUpload1.HasFile)
            {
                String fileName = ADMIN_FileUpload1.FileName;
                savePath += fileName;
                ADMIN_FileUpload1.SaveAs(savePath);
                FileName = fileName;
                FilePath = savePath;
                boolean = true;
            }
            else
            {
               Response.Write("<script language=javascript>alert('您没有选择一个文件进行上传!')</script>");
            }
            if (boolean) {
              DBAccess DB = new DBAccess();
                string strSql = " INSERT INTO Download  (filepath, filename) VALUES ('"+FilePath+"', '"+FileName+"')";
                DB.DealData(strSql);
                Response.Write("<script language=javascript>alert('上传成功!')</script>");
            }
        }以上是我写的代码 可是 怎么也无法获取字符串 修改不了数据库
请大家帮忙解决一下

解决方案 »

  1.   

    是不是没有权限上传到C:\\Documents and Settings\\Dang\\My Documents\\Visual Studio 2008\\WebSites\\新闻发布系统\\Upload\\
      

  2.   

    上传已经成功 只是无法获取FilePath 还有FileName两个字符串 
    我是想把这些路径放到一个数据库中 然后在下载的时候直接通过数据库生成下载的文件的列表
      

  3.   

    LZ自己输出下FilePath 还有FileName看看是不是你想要的数据
     if (FileUpload1.PostedFile.FileName != "")
            {
                try
                {
                    string FlvPath = FileUpload1.PostedFile.FileName;
                    string FlvName = FlvPath.Substring(FlvPath.LastIndexOf("\\") + 1);
                    string FlvExtend = FlvPath.Substring(FlvPath.LastIndexOf(".") + 1);
                    if (!(FlvExtend == "flv"))
                    {
                        message.Text = "上传图片的格式不正确!";
                        return;
                    }
                    string ServerPath = Server.MapPath("flv/") + FlvName;
                    FileUpload1.PostedFile.SaveAs(ServerPath);
                    SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["testConnectionString1"].ConnectionString);
                    con.Open();
                    SqlCommand com = new SqlCommand("insert into Video(VideoPath)values('" + FlvName + "')", con);
                    com.ExecuteNonQuery();
                    con.Close();
                    message.Text = "上传成功,图片名称为:" + FlvName;
                }
                catch (Exception se)
                {
                    message.Text = se.ToString();
                }
            }
      

  4.   

    这是一个上传图片的例子
    看看管不管用public void add()
        {
            //获取图片的基目录
            string path = AppDomain.CurrentDomain.BaseDirectory;
            //获得上传图片的名称
            string imgname = imgUp.FileName.ToString();
            string strFileName = this.imgUp.PostedFile.FileName;
            string strfileType = strFileName.Substring(strFileName.LastIndexOf('.') + 1).ToLower();        if (imgUp.HasFile)
            {
                if (imgUp.PostedFile.ContentType.ToLower() == "image/gif" || imgUp.PostedFile.ContentType.ToLower() == "image/pjpeg" || imgUp.PostedFile.ContentType.ToLower() == "image/bmp")
                {
                    string newFielName = DateTime.Now.Ticks.ToString() + "." + strfileType;
                    string strPath = Server.MapPath("/") + "ServerCenter\\admin\\Upload\\" + newFielName;
                    //调用缩略图构造方法
                    ImageClass imageClass = new ImageClass(imgUp.PostedFile.InputStream);
                    //调用缩略图方法
                    Boolean flag = imageClass.GetReducedImage(120, 110, strPath);                if (flag == true)
                    {
                        string newImgFiel = DateTime.Now.Ticks.ToString() + "" + DateTime.Now.Ticks.ToString() + "." + strfileType;
                        string strNewPath = Server.MapPath("/") + "ServerCenter\\admin\\Upload\\";
                        //保存原始图片到指定路径
                        this.imgUp.SaveAs(strNewPath + newImgFiel);
                        //调用缩略图构造方法(大图片)
                        ImageClass NewImageClass = new ImageClass(imgUp.PostedFile.InputStream);                    string sql = "insert into SJ_LP values(@lp_mc,@lp_sl,@lp_tpdz,@lp_sjjz,@lp_jdjg,@lp_yhjg,@lp_ystp,@lp_bz)";
                        SqlCommand cmd = new SqlCommand(sql, conn);
                        cmd.Parameters.AddWithValue("@lp_mc", TextBox1.Text.Trim());
                        cmd.Parameters.AddWithValue("@lp_sl", TextBox2.Text.Trim());
                        cmd.Parameters.AddWithValue("@lp_tpdz", @"admin\Upload\" + imgname);
                        cmd.Parameters.AddWithValue("@lp_ystp", @"admin\Upload\" + newImgFiel);
                        cmd.Parameters.AddWithValue("@lp_sjjz", double.Parse(TextBox4.Text.Trim()));
                        cmd.Parameters.AddWithValue("@lp_jdjg", TextBox5.Text.Trim());
                        cmd.Parameters.AddWithValue("@lp_yhjg", TextBox6.Text.Trim());
                        cmd.Parameters.AddWithValue("@lp_bz", Server.HtmlEncode(WebEditor1.Text));
                        conn.Open();                    if (cmd.ExecuteNonQuery() > 0)
                        {
                            conn.Close();
                            Response.Write("<script>alert('添加成功!');</script>");
                            showgift();
                        }
                        else
                        {
                            Response.Write("<script>alert('添加失败!');</script>");
                        }
                    }
                    else
                    {
                        Response.Write("<script>alert('添加失败!');</script>");
                    }
                }
                else
                {
                    Response.Write("<script>alert('服务器只允许上传gif、jpg、bmp格式的图片');</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('请选择图片');</script>");
            }
        }
      

  5.   


    或者是private void btnbuildurl_Click(object sender, EventArgs e)
            {
                FolderBrowserDialog f = new FolderBrowserDialog();
                if (f.ShowDialog() == DialogResult.OK)
                {
                    txtbuildurl.Text = f.SelectedPath;
                }
            }
      

  6.   

      if (ADMIN_FileUpload1.HasFile) 
                { 
                    String fileName = ADMIN_FileUpload1.FileName; 
                    savePath += fileName; 
                    ADMIN_FileUpload1.SaveAs(savePath); 
                    FileName = fileName; 
                    FilePath = savePath; 
                    boolean = true; 
     if (boolean) { 
                  DBAccess DB = new DBAccess(); 
                    string strSql = " INSERT INTO Download  (filepath, filename) VALUES ('"+FilePath+"', '"+FileName+"')"; 
                    DB.DealData(strSql); 
                    Response.Write(" <script language=javascript>alert('上传成功!') </script>"); 
                }             } 
                else 
                { 
                  Response.Write(" <script language=javascript>alert('您没有选择一个文件进行上传!') </script>"); 
                } 
               
      

  7.   


     string Savepath = Server.MapPath("../../../UpFile/StaPhoto/");//目标存放路径,写相对路径
     string fileName = FileUpload1.FileName;
      

  8.   

    我重说一下问题 上传功能是完全正确的 并且可以用的
    只是 无法获取FileName 和FilePath两个字符串 我单个用Label.text尝试过 显示的是正确的 但是就是如上传参数的时候无法正确给Sql语句
    我想问问是不是长传过程造成页面重新启动 使得参数丧失了?