1

AjaxFileUploader を使用して、ASP.net プロジェクトに複数のファイルをアップロードしています。

ファイルを 4 MB にアップロードする前にファイル サイズを検証したい。

私のコードは次のとおりです。

 <ajaxToolkit:AjaxFileUpload
    id="ajaxUpload1" OnUploadComplete="ajaxUpload1_OnUploadComplete"
    ThrobberID="MyThrobber1" MaximumNumberOfFiles="5" runat="server" AllowedFileTypes="swf,pdf"></ajaxToolkit:AjaxFileUpload>

    <asp:Image id="MyThrobber1" ImageUrl="~/images/loading.gif" Style="display:None" runat="server" />

  protected void ajaxUpload1_OnUploadComplete(object sender, AjaxFileUploadEventArgs e)
    {

            int fileSize = e.FileSize;

                // fileSize in bytes
                if (fileSize < 4194304)
                {
                    //String currentDir = FileManager1.CurrentDirectory.PhysicalPath;
                    String FilePath = Path.Combine(currentDir, e.FileName);

                    // Save upload file to the file system
                    ajaxUpload1.SaveAs(FilePath);

                }

   }
4

1 に答える 1

-1

更新されたこれを試してください:

protected void ajaxUpload1_OnUploadComplete(object sender, AjaxFileUploadEventArgs e)
{
   try
   {
           int fileSize = e.FileSize;

     //String currentDir = FileManager1.CurrentDirectory.PhysicalPath;
      String FilePath = Path.Combine(currentDir, e.FileName);
            // fileSize in bytes
            if (fileSize > 4194304)
            {
             ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "SelectDetails", "alert('You Exceed the limit.');", true);    
              return;

            }
                // Save upload file to the file system
                ajaxUpload1.SaveAs(FilePath);
    }

 catch (Exception ex)    
  {
    throw ex;
  }

}
于 2013-10-16T12:24:46.877 に答える