当文件上传量超过12 MB时,该怎么办?

时间:2013-08-06 09:59:21

标签: asp.net

当我上传文件时。大于12mb的文件没有上传,会话过期

protected void populateCategoryList()
{
    try
    {
        string strCon = ConfigurationManager.ConnectionStrings["mcqConnectionString"].ConnectionString;
        SqlConnection conn = new SqlConnection(strCon);

        SqlCommand command = new SqlCommand("usp_MCQ_GetCategories", conn);
        command.CommandType = CommandType.StoredProcedure;
        command.Parameters.Add(new SqlParameter("@type", "Video"));
        conn.Open();
        SqlDataAdapter adapter = new SqlDataAdapter(command);
        conn.Close();

        DataSet ds = new DataSet();
        adapter.Fill(ds, "CategoryList");

        lbCategory.Controls.Clear();
        if (ds.Tables.Count > 0)
        {
            DataTable result = ds.Tables[0];
            if (result.Rows.Count > 0)
            {
                for (int i = 0; i < result.Rows.Count; i++)
                {
                    DataRow odrMain = result.Rows[i];
                    if (odrMain["parent_cat"].ToString().Trim() == "0" || odrMain["parent_cat"].ToString().Trim() == "")
                    {
                        lbCategory.Items.Add(new ListItem(odrMain["name"].ToString(), odrMain["id"].ToString()));

                        for (int k = 0; k < result.Rows.Count; k++)
                        {
                            DataRow odr = result.Rows[k];
                            if (odr["parent_cat"].ToString().Trim() == odrMain["id"].ToString().Trim())
                            {
                                lbCategory.Items.Add(new ListItem("\xA0\xA0\xA0\xA0" + odr["name"].ToString(), odr["id"].ToString()));
                            }
                        }
                    }
                }
            }
        }
    }
    catch (Exception ex)
    {
        //exception handling
    }
}

protected void createMedia_Click(object sender, EventArgs e)
{
    string rootPath = Server.MapPath("~/videos/");
    if (FileUploadVideos.FileName.Contains(".mp4") || FileUploadVideos.FileName.Contains(".MP4") || FileUploadVideos.FileName.Contains(".mp3") || FileUploadVideos.FileName.Contains(".MP3"))
    {
        string selectedCategories = "";
        for (int i = 0; i < lbCategory.Items.Count; i++)
        {
            if (lbCategory.Items[i].Selected)
            {
                selectedCategories += lbCategory.Items[i].Value + ",";
            }
        }
        int[] status = new int[2];
        status = SQLHelper.createVideo(tbTitle.Text.Trim(), selectedCategories, Path.GetExtension(FileUploadVideos.FileName), Path.GetExtension(FileUploadPoster.FileName));

        if (status[0] == 1)
        {
            ErrorMessage.Text = "Media added sucessfully. Use above form to add another Video/Podcast";
            FileUploadVideos.SaveAs(rootPath + status[1].ToString() + Path.GetExtension(FileUploadVideos.FileName));
            if (FileUploadPoster.HasFile)
            {
                FileUploadPoster.SaveAs(rootPath + status[1].ToString() + Path.GetExtension(FileUploadPoster.FileName));
            }

            emptyFields();
        }
        else if (status[0] == -1)
            ErrorMessage.Text = "Media already exists. Please try some other Title";
        else
            ErrorMessage.Text = "Some error occured. Please try again. If problem persists conatct your administrator";
    }
    else
    {
        ErrorMessage.Text = "Only MP4 media is allowed to upload.";
    }
}

2 个答案:

答案 0 :(得分:1)

您是否确定web.config中的设置正常? maxrequestlength是以KB为单位的文件大小,执行超时是超时前的时间,以秒为单位。

<httpRuntime  maxRequestLength="90240" executionTimeout="420"/>

答案 1 :(得分:1)

请参阅此link

尝试调整web.config中的maxRequestLength。

  <system.web>
    <httpRuntime maxRequestLength="[number in KB]" />
  </system.web>