Click here to Skip to main content
12,069,894 members (68,336 online)
Click here to Skip to main content
Articles » Web Development » Ajax » Samples » Downloads

Stats

34K views
454 downloads
68 bookmarked
Posted

Professional file uploads with the MultiUpload and ImageList server controls

, 20 Dec 2007 GPL3
A professional AJAX GUI for uploading files using the server controls in the Memba Velodoc XP Edition.
proupload_src.zip
ProUpload
App_Data
Bin
Memba.WebControls.XP.dll
images
upload.gif
scripts
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.IO; //Directory, Path, FileInfo

public partial class _Default : System.Web.UI.Page 
{
    private const string TARGET_DIR = "~/";

    protected void SubmitButton_Click(object sender, EventArgs e)
    {
        //Check target directory
        string sTargetDir = Request.MapPath(TARGET_DIR);
        System.Diagnostics.Debug.Assert(Directory.Exists(sTargetDir));

        //Iterate through posted files (foreach does not work with empty file inputs)
        for (int i = 0; i < Request.Files.Count; i++)
        {
            HttpPostedFile objFile = Request.Files[i];
            //Make sure file input has content
            if ((objFile.ContentLength > 0) && (objFile.FileName.Length > 0))
            {
                //Get target file path for save as
                string sFileName = Path.GetFileName(objFile.FileName);
                string sFilePath = Path.Combine(sTargetDir, sFileName);
                FileInfo objFileInfo = new FileInfo(sFilePath);
                //No business rule, i.e. we just want to avoid failure
                if (objFileInfo.Exists)
                {
                    objFileInfo.Attributes &= ~FileAttributes.ReadOnly;
                    objFileInfo.Delete();
                }
                //Save file
                objFile.SaveAs(sFilePath);
            }
        }

        //Clear the list, otherwise the ImageList has items
        //Which the MuliUpload component does not have
        ImageList.ImageListItemCollection.Clear();
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

jlchereau
Other Memba
United Kingdom United Kingdom

Other Articles:

My work at Memba

You can check what Memba does at our corporate web site.

I am currently working on two projects:
- VELODOC, a file transfer online service and software product which you can try at http://www.velodoc.net;
- CITADOC, a knowledge base/wiki online service and software product which can be managed and edited in Microsoft Office and which will be released in the second half of 2008.

The XP edition of these projects is the open source core released under the GPL license.


You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160208.1 | Last Updated 20 Dec 2007
Article Copyright 2007 by jlchereau
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid