For C# developers. C# - Upload Multiple Files with Thumbnail, Folders, and SQL Server Database
In 2011, I created the Uploadify vb.net script for uploading multiple files to a specified folder listed in the code. However, the Uploadify Flash component is no longer supported in major browsers, so I had to look around for something else to use on our websites and future projects.
I came across one that I liked but could not get to work on the IIS web server. So, after not coming up with another alternative, I took the advice of a fellow programmer named David on the website Experts Exchange«. David suggested I create my own, so I would have complete control over what it does and would ensure it worked in IIS, so that is what I did.
Instead of reinventing the wheel, I searched for a premade JQuery multiple upload script with thumbnail for ASP.NET. I did not care if it supported vb.net, as I would be able to convert it over to VB if needed quickly using the online conversion tool, Telerik.«.
After a quick 2-minute search, I found a thread on aspsnippets.com« which did precisely what I was needing.
The code only uploads files to a designated folder in code, so the rest I had to do on my own, and so I started harming away at the code to make it work to what I needed it to do.
In the script below, you will find everything you need to make it work straight from the box. An instructional video will also be available when the site is live to help you through any issues you may encounter along the way.
What this script does.
- Written in VB.NET, this upload script is very robust, allowing you to upload many files. Easily changed in the web.config file and the JS script.
- Page checks if there is a QueryString("ID") available. If not, a warning is given with a link to click. The buttons on the page are also disabled until a valid ID is present. This part can be expanded to include a check against a database to ensure the user who uploads the images has a valid ID and is logged in to their account before everything is set and available.
- If the file is larger than the set file size, it will show an error, and the file will not be available for uploading.
- Create two folders, Big and Thumbs, with the ability to add more folders easily within the aspx.vb file and within the web.config file.
- Images are resized using the resizeImage() function. Images are not only smaller in diameter but pixel size as well.
- Information inserted into SQL Server Database. (Included Table Script)
The database table information is listed here.
Table name: ImageServer
- [PicsID] [int] IDENTITY(1,1) NOT NULL,
- [PicsFolder] [nvarchar](50) NULL,
- [Userid] [int] NULL,
- [DefaultFolder] [int] NULL,
- [PicsPath] [varchar](255) NULL,
- [PicsName] [nvarchar](50) NULL,
- [PicsSize] [int] NULL,
- [PicWH] [varchar](50) NULL,
- [PicDate] [datetime] NULL,
- [DateUpdated] [datetime] NULL,