2012-05-17 92 views
0
 protected void Button1_Click(object sender, EventArgs e) 
     { 
      //Uploading file from Computer to Database(server) 
      String filename = "", filetype = "", filesize = ""; 
      if (FileUpload1.HasFile) 
      { 
       UploadLogic bl=new UploadLogic(); 
       filename = FileUpload1.PostedFile.FileName; 
       filesize = FileUpload1.PostedFile.ContentLength.ToString(); 
       filetype = FileUpload1.PostedFile.ContentType; 
       byte[] filepath = new byte[FileUpload1.PostedFile.ContentLength]; 
       FileUpload1.PostedFile.InputStream.Read(filepath, 0, FileUpload1.PostedFile.ContentLength); 
       int i = bl.upload_file(filename, filesize, filetype, filepath); 
       DataSet ds = new DataSet(); 
       ds = bl.uploaded_Content(); 
       ListBox1.DataSource = ds; 
       ListBox1.DataTextField = "File_Name"; 
       ListBox1.DataValueField = "File_Name"; 
       //Bind your Data 
       ListBox1.DataBind(); 
      } 

     } 

該代碼只上傳小於1MB的文件。如果我想上傳大文件不會發生。任何人都可以告訴我爲什麼?如何在DataBase中上傳大文件?

+2

文件不uplaod爲DB。反而保存他們的位置! –

+0

請定義「巨大」。 – KingCronus

+2

用大文件扼殺數據庫是一種很好的殺死系統的方法 – Alex

回答

1

看一看httpRuntime

你需要編輯web.config

<configuration> 
    <system.web> 
    <httpRuntime maxRequestLength="SIZE" /> 
    </system.web> 
</configuration> 

默認情況下,將被設置爲4096kb

無論如何,如果文件大小是相當高的,將是將文件上傳到數據庫是一個很好的解決方案。

+1

Size參數以KB爲單位表示。例如,如果您希望最大8MB,請將其設置爲8192 –

+0

默認情況下,它的4096kb?意味着4MB ..對嗎? –

+0

然後,如果我加載2MB文件,它會拋出一個錯誤..像操作超時 –

1

編輯你的web.config

<httpRuntime useFullyQualifiedRedirectUrl="true|false" 
      maxRequestLength="size in kbytes" 
      executionTimeout="seconds" 
      minFreeThreads="number of threads" 
      minFreeLocalRequestFreeThreads="number of threads" 
      appRequestQueueLimit="number of requests" 
      versionHeader="version string"/> 

來源 Element