电子邮件附件不再作为自定义样式 ASP:FileUpload 字段工作

Email Attachment No Longer Working As Custom Styled ASP:FileUpload Field

我有一个允许文件上传的 asp.net 应用程序,我可以正常工作,但现在我已经自定义了我的文件上传字段的样式,它不再工作,我不知道如何获取它再次使用我的新样式字段。

旧 HTML

<div class="form-group">
    <asp:Label ID="Label3" class="col-md-3 control-label" runat="server" Text="Upload"></asp:Label>
    <div class="col-md-3">
        <asp:FileUpload ID="fuAttachment" runat="server" class="fileupload"></asp:FileUpload>
    </div>
</div>

旧代码隐藏

    var file = fuAttachment.PostedFile;
    if (file != null && fuAttachment.PostedFile.FileName != "")
    {
        var content = new byte[file.ContentLength];
        file.InputStream.Read(content, 0, content.Length);
        Session["FileContent"] = content;
        Session["FileContentType"] = file.ContentType;
        Session["File"] = fuAttachment.FileName;
        Session["AttachmentProvided"] = "Yes";
    }

新 HTML

    <div class="fileinput fileinput-new input-group" data-provides="fileinput">
        <div class="form-control" data-trigger="fileinput" style="background-color: #ededed">
            <span class="fileinput-filename"></span>
        </div>
        <span class="input-group-addon btn btn-default btn-file">
            <span class="fileinput-new">
                <span class="glyphicon glyphicon-folder-open" title="Click to select a file."></span>
            </span>
            <span class="fileinput-exists">
                <span class="glyphicon glyphicon-folder-open" title="Click to change the selected file."></span>
            </span>
            <input type="file" name="...">
        </span>
        <a href="#" class="input-group-addon btn btn-default fileinput-exists" data-dismiss="fileinput">
            <span class="glyphicon glyphicon-remove" title="Remove selected file."></span>
        </a>
    </div>

我需要存储在我的会话中,因为这会填充另一个页面,所以我需要与之前的代码类似的代码

编辑文件输入到:

<input type="file" id="fuAttachment" runat="server" />

现在您可以使用代码隐藏中的 fuAttachment 来访问上传的文件。

注意:如果缺少 runat="server" 属性,您将无法从代码隐藏控制此输入。