hey all,

i am developing a user control which will show a hidden div for uploading files. the idea is to upload multiple file at once. does anyone knows how to do that ?

thanks...

NOTE: the control will be built using ASP.NET and C#.

Dani AI

Generated

A few practical approaches and pitfalls for a hidden-div multiple-upload control in ASP.NET/C#.

A simple, modern option is an HTML5 file input that supports multiple selection on capable browsers:

<input type="file" name="files" id="files" multiple />

If you must support older browsers, dynamically add more <input type="file"> elements with JavaScript, or use an upload widget/library that provides fallbacks.

Server-side handling (WebForms example): loop Request.Files, validate each file, sanitize the name, and save with a unique filename to avoid collisions:

for (int i = 0; i < Request.Files.Count; i++)
{
    var posted = Request.Files[i];
    if (posted != null && posted.ContentLength > 0)
    {
        var fileName = Path.GetFileName(posted.FileName);
        // validate extension and size here
        var savePath = Path.Combine(Server.MapPath("~/Uploads"),
                                    Guid.NewGuid().ToString() + "_" + fileName);
        posted.SaveAs(savePath);
    }
}

Notes and troubleshooting (based on the thread):

  • As referenced, there are many sample implementations; pick one that fits your browser support needs.
  • As observed, do not use shared/static collections (like a static ArrayList) to accumulate uploads — that produces cross-user race conditions. Keep per-request state (local lists, HttpContext.Items, a session key per upload GUID, or a per-upload temp folder).
  • Ensure the form uses enctype="multipart/form-data". Configure limits in web.config (<httpRuntime maxRequestLength="...">) and IIS (maxAllowedContentLength) for large uploads.
  • Give the app write permission to the target folder, validate extensions and sizes, sanitize filenames to prevent path traversal, and generate unique names. Avoid storing large raw file bytes in Session to prevent memory issues.

If you want progress UI or chunked/large-file support, use XHR2/FormData with server-side chunk assembly or a proven client library that handles browser fallbacks and retries.

Recommended Answers

All 2 Replies

this code works only for single more than one client use the upload ,then there is bug in application due to SHARED array list.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.