-1

ファイルをアップロードしているとき。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.";
    }
}
4

2 に答える 2