File Upload with VB.NET
How This Works
The values sFileDir and lMaxFileSize have been hard coded at the top and instead can be retrieved from either a database or an XML configuration file. sFileDir specifies the location where on the server the copied file is to be saved. lMaxFileSize specifies the maximum allowed file size for an uploaded file.
The DeleteFile procedure is used to delete the copied file from the server. As a part of the normal cleanup process, after the file upload takes place, the file will be moved either to the database or to some other location on the server depending on the application requirements. In the example, you don't copy the file anywhere so you don't call this procedure unless an error occurs and you need to get rid of the file. DeleteFile can be called after the file has been moved into the database or to another location for cleaning purposes. It accepts a full file name (directory and file name) as one argument and verifies that the file exists and that the length of the argument is bigger than 0. Then, it attempts to delete the file by using the FileInfo object.
Note: When uploading files, keep in mind that ASP.NET limits the file size of the uploaded files to 4 MB or 4096 KB. If you try to upload a file that is larger than that, you will get an error. You can change that setting by changing the maxRequestLength setting in the httpRuntime element of the Machine.config file. See Microsoft's web site for more information.
In this sample, you demonstrated a simple way of providing users with an upload document functionality by using ASP.NET and VB.NET.
About the Author
Irina Medvinskaya has been involved in technology since 1996. Throughout her career, she as developed many client/server and web applications, mainly for financial services companies. She works as a Development Manager at Citigroup.
Page 2 of 2