文件上载控制无效

时间:2022-10-18 17:38:48

File name and extension are empty. Please help.

文件名和扩展名为空。请帮忙。

ASPX FILE CODE:

ASPX文件代码:

<tr>
  <td colspan="3" style="height:0px">
    <div id="trFile" runat="server" class="inlineGridAddAddress">
      <table cellpadding="0" cellspacing="0">
        <tr>
          <td>
            <div class="formFieldName">
              <asp:RequiredFieldValidator ID="reqFile" runat="server"
                  ControlToValidate="fileUpload" ErrorMessage="Please select File"
                  ValidationGroup="Save" CssClass="Validations" ></asp:RequiredFieldValidator>
            </div>
          </td>
        </tr>
        <tr>
          <td>
            <asp:Label ID="lblFile" runat="server">File:</asp:Label>
          </td>
          <td>
            <div>
              <asp:FileUpload ID="fileUpload" runat="server" />
            </div>
          </td>
          <td class="tdformFieldValueLogin" style="width:350px;padding-left:50px">
            <asp:ImageButton ID="btnFileUploadSave" runat="server" ValidationGroup="Save"
                ImageUrl="~/App_Themes/Default/images/update.png" ToolTip="Save"
                Height="18px" onclick="btnFileUploadSave_Click"/>
            <asp:ImageButton ID="btnFileUploadCancel" ImageUrl="~/App_Themes/Default/images/cancel.png"
                runat="server" ToolTip="Cancel" Height="18px" />
          </td>
        </tr>

        <tr>
          <td>
            <div class="formSmallTextAreaName">
              <asp:Label ID="lblDescription" runat="server">Description:</asp:Label>
            </div>
          </td>
          <td>
            <div class="formSmallTextAreaValue">
              <asp:RegularExpressionValidator ID="revNote"
                  runat="server" ControlToValidate="txtDescription"
                  ValidationExpression="^[\s\S]{0,4096}$"
                  Text="Maximum 4096 characters are allowed."
                  CssClass="Validations" Display="Dynamic">
              </asp:RegularExpressionValidator>
              <asp:TextBox ID="txtDescription"
                  runat="server" CssClass="textEntry1"
                  TextMode="MultiLine" MaxLength="4096" Width="218px">
              </asp:TextBox>
            </div>
          </td>
        </tr>
      </table>
    </div>
  </td>
</tr>

CS FILE CODE:

CS文件代码:

protected void btnFileUploadSave_Click(object sender, ImageClickEventArgs e)
    {
        string path = Server.MapPath(".") + "\\Files\\" + this.fileUpload.FileName;
        string fileExtension = System.IO.Path.GetExtension(this.fileUpload.FileName).ToLower();
        if (fileExtension == ".txt" || fileExtension == ".doc" || fileExtension == ".docx" || fileExtension == ".zip" || fileExtension == ".rar" || fileExtension == ".cs" || fileExtension == ".ppt" || fileExtension == ".pdf" || fileExtension == ".html" || fileExtension == ".jpg" || fileExtension == ".gif" || fileExtension == ".bmp" || fileExtension == ".png" || fileExtension == ".tif" || fileExtension == ".rm" || fileExtension == ".mp3" || fileExtension == ".xls")
        {
            this.fileUpload.PostedFile.SaveAs(path);
        }
    }

1 个解决方案

#1


8  

If you're putting your UploadControl in an UpdatePanel (Ajax stuff), it won't work by default. Use Update Panel, File Upload Control and use a PostBackTrigger Control to force a postback only for the File Upload Control

如果您将UploadControl放在UpdatePanel(Ajax的东西)中,默认情况下它将不起作用。使用“更新面板”,“文件上载控件”并使用PostBackTrigger控件仅强制执行文件上载控件的回发

Check out the following link

查看以下链接

File Upload in UpdatePanel, ASP.NET AJAX

在UpdatePanel,ASP.NET AJAX中上传文件

#1


8  

If you're putting your UploadControl in an UpdatePanel (Ajax stuff), it won't work by default. Use Update Panel, File Upload Control and use a PostBackTrigger Control to force a postback only for the File Upload Control

如果您将UploadControl放在UpdatePanel(Ajax的东西)中,默认情况下它将不起作用。使用“更新面板”,“文件上载控件”并使用PostBackTrigger控件仅强制执行文件上载控件的回发

Check out the following link

查看以下链接

File Upload in UpdatePanel, ASP.NET AJAX

在UpdatePanel,ASP.NET AJAX中上传文件