Issue with upload in grid edit form

4 posts, 1 answers
  1. Senthil
    Senthil avatar
    7 posts
    Member since:
    Aug 2013

    Posted 29 Aug 2013 Link to this post

    There is a radgrid in my web application and I am displaying its edit form a user control. The grid edit form has an upload control to upload files. All were working fine when I run this application from localhost and once this application is moved to IIS7 on the windows server 2008 production server, the upload is not working. Everything works fine if I edit without upload a file. If I upload a file and try to save the edit form, IE displays it cannot find display the page and MF says that the connection has been reset.

    Not sure what is causing this issue with the same application on IIS.
    Senthil
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 30 Aug 2013 Link to this post

    Hi Senthil,

    Such an issue can happen when you are trying to upload large files. Try the following settings for IIS 7 in the web.config file.

    XML:
    <system.webserver>
    ...
    <security >
        <requestFiltering>
            <requestLimits maxAllowedContentLength="1024000000" />
        </requestFiltering>
    </security>
    </system.webserver>

    Open the file C:\Windows\System32\inetsrv\config\applicationHost.config and find the line:

    <section name="requestFiltering" overrideModeDefault="Deny" />

    Set the overrideModeDefault property to Allow.

    You can also set a higher value for the executionTimeout property since network traffic can also sometimes lead to such an issue.

    Thanks,
    Shinu.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Senthil
    Senthil avatar
    7 posts
    Member since:
    Aug 2013

    Posted 05 Sep 2013 Link to this post

    Thanks shinu. I fixed the problem with web.config. Heres another requirement. The scenario is to upload files with total size not exceeding 5 mb. I need C# and suppose the size exceed 5mb the rest of the files shouldnt be saved on the server and discarded. Also alert user about those files which are not uploaded.
  5. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 06 Sep 2013 Link to this post

    Hi Senthil,

    Please have a look into the following code I tried which works fine at my end.

    ASPX:
    <div>
        Select Files with total size upto 5 MB.<br />
        <br />
        <telerik:RadAsyncUpload runat="server" ID="RadAsyncUpload1" Skin="Silk" TargetFolder="~/Images/Img/"
            AllowedFileExtensions=".jpg,.zip" MaxFileSize="579371152" MultipleFileSelection="Automatic"
            UploadedFilesRendering="BelowFileInput" OnFileUploaded="RadAsyncUpload1_FileUploaded">
        </telerik:RadAsyncUpload>
        <br />
        <br />
        <telerik:RadButton ID="RadButton1" runat="server" Text="Upload" OnClick="RadButton1_Click">
        </telerik:RadButton>
        <asp:HiddenField ID="HiddenField1" runat="server" />
    </div>

    C#:
    const int MaxTotalBytes = 5242880;
    Int64 UploadedBytes;
     
    protected void Page_Load(object sender, EventArgs e)
    {
     
    }
    protected void RadAsyncUpload1_FileUploaded(object sender, Telerik.Web.UI.FileUploadedEventArgs e)
    {
        UploadedBytes += e.File.ContentLength;
        if (UploadedBytes <= MaxTotalBytes)
        {
            string targetfolder = RadAsyncUpload1.TargetFolder;
            e.File.SaveAs(Path.Combine(Server.MapPath(targetfolder), e.File.FileName));  
        }
        else
        {
            e.IsValid = false;
            UploadedBytes -= e.File.ContentLength;
            HiddenField1.Value = HiddenField1.Value + e.File.FileName + " ";
        }
    }
    protected void RadButton1_Click(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(HiddenField1.Value))
        {
            Response.Write("<script>alert('" + HiddenField1.Value + "'+' not uploaded')</script>");
        }
        HiddenField1.Value = "";
    }

    Thanks,
    Shinu.
Back to Top