Question

When uploading files to a server what information should be provided to the user for feedback? I have created a website that allows users to upload files to a server. I would think a progress bar would be nice or at the very least a message to let the users know that the process was successful or not. Another issue is how do I know that the operation was successful? Right now the only thing I can think of is to check if the files exist after they are saved. I am using C# .NET 2.0 on the server side. Here is an example of the code I have for saving the files...

private void fileUpload(HttpContext context)
{   
    string stgDir = @"myDir",
           fullPath;

    HttpFileCollection hfc = context.Request.Files;
    for(int i = 0; i <  hfc.Count; i++)
    {
        fullPath = Path.Combine(BASE_PATH, stgDir);

        if(!Directory.Exists(fullPath))
        {
            Directory.CreateDirectory(fullPath);
        }
        if(hfc[i].ContentLength > 0)
        {
            fullPath = Path.Combine(fullPath,hfc[i].FileName);
            hfc[i].SaveAs(fullPath);
        }
    }
} 
Was it helpful?

Solution

If you don't get an exception is very unlikely that there was an error saving the file, so, add a try catch and show your user an error if exception is catch, or just a friendly message indicating the file was uploaded. Regarding the info as feedback, that's up to you and what you would like the user to know, maybe success message and a link to the file would be enough.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top