In my ASP.Net application I have to allow user to attach files (doc, xls, pdf, zip, txt) etc. The way we need to setup the interface is that user chooses file(s) using FileUpload tool and clicks the "Add" button. On "Add" button, file is added to a GridView with file name, size, comments information. User may add upto 10 files per Project/Quotation/Invoice/Task/SubProject. Once user clicks "Update Project" or "Create Project" (Depending on which mode/module user is in), the files are saved to database with File name, size, type, comments, content (binarymax) information. Currently I store the contents of the files in ViewState. So the problem is page size increases too much if user uploads files of greater size.
So, what is the best way to fix this? I dont have the Project id, while in "Project Create" mode so that I can straight away send the data to database on "Add" button click. How should I handle this scenario?
P.S: Maximum size per file is 10 MB."
Well one option is that you can create a clone table from your current table (let's call it files_tmp) in your database. When user is in "insertion" mode, you'll generate a random project ID and save it in ViewState("TmpProjID"). Now every time user clicks save in the GridView, save all your file info into the files_tmp table with using the temp project ID.
For the file contents, I'd save them in a temp folder using the temp project id as the folder name as well.
Finally when the user clicks the save button, select all the records from project_tmp table where project id = ViewState("TmpProjID") and insert them into your original table, then copy all the file contents from the temp folder and put them in the original folder and delete them from the temp folder after saving.