当前位置:编程学习 > C#/ASP.NET >>

在网站后台上传影片失败?

我制作的是视频网站
在后台上传影片
总是失败
求高手解答



using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Manage_upmov : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.databind();
            int id = Convert.ToInt32(Request.QueryString["movid"]);
            SqlConnection con = DB.getcon();
            SqlCommand cmd = new SqlCommand("select*from Movies where MovID='" + id + "'", con);
            con.Open();
            SqlDataReader dr = cmd.ExecuteReader();

            if (dr.Read())
            {
                this.TextBox1.Text = dr["MovName"].ToString();
                this.TextBox2.Text = dr["Movdirector"].ToString();
                this.TextBox3.Text = dr["MovActor"].ToString();
                this.TextBox4.Text = dr["MovTime"].ToString();
                this.TextBox5.Text = Convert.ToDateTime(dr["MovStartData"]).ToShortDateString();
                this.TextBox6.Text = dr["MovCountry"].ToString();
                this.TextBox7.Text = dr["MovLanguage"].ToString();
                this.TextBox9.Text = dr["MovDec"].ToString();
                this.DropDownList1.SelectedValue = dr["CatID"].ToString();

            }
            dr.Close();
            con.Close();

        }

    }
    public void databind()
    {
        SqlConnection con = DB.getcon();
        string sqlstr = "select*from Categories";
        DataSet ds = new DataSet();
        SqlDataAdapter sda = new SqlDataAdapter(sqlstr, con);
        sda.Fill(ds, "cate");
        this.DropDownList1.DataSource = ds.Tables["cate"].DefaultView;
        this.DropDownList1.DataTextField = "CatName";
        this.DropDownList1.DataValueField = "CatID";
        DropDownList1.DataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string mname = this.TextBox1.Text;
        string mclass = this.DropDownList1.SelectedValue.ToString();
        string director = this.TextBox2.Text;
        string actor = this.TextBox3.Text;
        int length = Convert.ToInt32(this.TextBox4.Text);
        DateTime dt = Convert.ToDateTime(this.TextBox5.Text);
        string country = this.TextBox6.Text;
        string laguage = this.TextBox7.Text;
        string dec = this.TextBox9.Text;
        DateTime current = DateTime.Now;
        string dtt = current.Year + "年" + current.Month + "月" + current.Day + "日";
        if (Page.IsValid)
        {
            Boolean fileok = false;
            string path = Server.MapPath("~/UploadImages");
            if (FileUpload1.HasFile)
            {
                string fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
                string[] allowedExtensions ={ ".gif", ".jpg", ".png", ".jpeg" };
                for (int i = 0; i < allowedExtensions.Length; i++)
                {
                    if (fileExtension == allowedExtensions[i])
                    {
                        fileok = true;
                    }
                }
            }
            if (fileok)
            {
                try
                {
                    FileUpload1.PostedFile.SaveAs(path + FileUpload1.FileName);
                    string picpath = "UploadImages/" + FileUpload1.FileName;
                    SqlConnection con = DB.getcon();
                    string sqlstr = "update  Movies  set CatID='" + mclass + "',MovName='" + mname + "',Movdirector='" + director + "',MovActor='" + actor + "',MovDec='" + dec + "',MovStartData='" + dt + "',MovTime='" + length + "',HitNum=0,AddDate='" + dtt + "',MovCountry='" + country + "',MovLanguage='" + laguage + "',MoveImage='" + picpath + "' where MovID='" + Request.QueryString["movid"] + "'";
                    SqlCommand cmd = new SqlCommand(sqlstr, con);
                    con.Open();
                    try
                    {
                        cmd.ExecuteNonQuery();
                        Response.Write("<script laguage='javascript'>alter('更新成功!');window.location.href('ManageVedios.aspx')</script>");
                    }
                    catch (Exception e1)
                    {
                        Response.Write(e1.Message);
                    }
                    con.Close();

                }
                catch (Exception e2)
                {
                    Response.Write(e2.Message);
                }
            }
            else
            {
                Response.Write("<script laguage='javascript'>alter('更新失败!');window.location.href('ManageVedios.aspx')</script>");
            }

        }
    }

    public void listbind()
    {
        SqlConnection con = DB.getcon();
        SqlCommand cmd = new SqlCommand("select*from Categories", con);
        con.Open();
        SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
        this.DropDownList1.DataSource = dr;
        this.DropDownList1.DataTextField = dr["CatName"].ToString();
        this.DropDownList1.DataValueField = dr["CatID"].ToString();
        this.DropDownList1.DataBind();
    }



} --------------------编程问答-------------------- 保证你上传到的文件夹开了写入权限 --------------------编程问答-------------------- 代码一大堆...
 SqlCommand cmd = new SqlCommand(sqlstr, con); 跟踪到此,拷贝sqlstr的内容在数据库直接执行,看能否通过?

另:
工具---IE选项,---高级---取消显示友好http错误信息,做开发的应该整掉这个啊
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,