2013-08-06 38 views
-1

當我上傳文件。文件大於12mb不上傳和會話過期,而這樣做當文件未上傳大於12 MB時可以執行哪些操作?

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."; 
    } 
} 

回答

1

你確定你在web.config中的設置是好的? maxrequestlength是以KB爲單位的文件大小,執行超時是超時前的時間,以秒爲單位。

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

請參閱此link

嘗試調整web.config中的maxRequestLength。

<system.web> 
    <httpRuntime maxRequestLength="[number in KB]" /> 
    </system.web> 
相關問題