I have an ASP.NET page that has a FileUpload control inside. When I try to upload a third file I am getting:

System.OutOfMemoryException at System.Convert.FromBase64String(String s) at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) at System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState) at System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState) at System.Web.UI.HiddenFieldPageStatePersister.Load()

here's my code:

<td style="width: 60%; height: 67px; vertical-align: top">
    <div class="fileinputs" id="div2" style="left: 0px; top: 0px; width: 100%; vertical-align: middle">
        <div id="div3" class="fakefile" style="left: 0px; top: 0px; vertical-align: middle">
            <asp:TextBox ID="txtFileUpload" runat="server" Width="265px" CssClass="borde-form"
                Height="15px" ValidationGroup="docs" />
            <img name="imgExaminar" alt="Examinar" src="../../Images/botExaminar.gif" style="cursor: hand;
                width: 81px; height: 20px; vertical-align: middle" />
        </div>
        <asp:FileUpload EnableViewState="true" ID="fileUpload" runat="server" Width="368px"
            Height="19px" CssClass="hidden" />
    </div>
    <asp:CustomValidator ID="cvattachment" runat="server" OnServerValidate="cvattachment_ServerValidate"
        ControlToValidate="fileUpload" ErrorMessage="Existe un archivo con el mismo nombre"
        Font-Bold="False" Font-Names="Arial" Font-Size="X-Small" ValidationGroup="docs"></asp:CustomValidator>
</td>
<td style="width: 30%; height: 67px; vertical-align: top">
    <asp:ImageButton ID="imgAdjuntar" runat="server" ImageUrl="~/Images/botAdjuntar.GIF"
        OnClick="imgAdjuntar_Click" ValidationGroup="docs" Height="20px" Width="66px"></asp:ImageButton>
</td>

When I click on my imgAdjuntar, I am getting the error, but the imgAdjuntar_Click method is never called, but the Application_Error on the Global.asax is fired instead. Plus, none of my breakpoints are being stepped into, the error occurs before reaching the application code.

Maybe the control is the one that's failing? What can I do?

Thank you!

有帮助吗?

解决方案

Make sure that you are not storing files within the ViewState.

In addition, try to disable the ViewState for the entire page.

Check the following treads, which may be helpful:

How do i handle 'System.OutOfMemoryException' in uploading?

Exception of type 'System.OutOfMemoryException' was thrown

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top