0

I have been struggling with this issue for some time now. I have a web interface where I create projects, with this you should be able to upload multiple documents to the server, which is attached to the project they belong to. So far I made it work with only uploading one file at a time.

My idea was maybe to add the "file" objects in an arralylist and then bind it to a gridview and then upload it to the server? I know this sound a bit confusing, but I'm confused also!

This is how my method look like when I upload a single file to the server and also save the file's ID, name and context in the database:

                File file = new File();
                Projects_Overview po = new Projects_Overview();
                po.Name = TextBoxName.Text;
                po.Time = time;
                po.Owner = TextBoxOwner.Text;
                po.Responsibility = TextBoxResp.Text;
                po.Created = datecreate;
                po.StartDate = datestart;
                po.FinishDate = datefinish;
                po.ETC = dateETC;
                po.Description = TextBoxDesc.Text;
                po.Comments = TextBoxComments.Text;
                po.Remember = TextBoxRemember.Text;

                ie.Projects_Overview.AddObject(po);
                ie.SaveChanges();

                if (uploadFile.HasFile)
                {
                    string filepath = uploadFile.PostedFile.FileName;
                    string fileName = Path.GetFileName(filepath);


                    file.Context = Path.GetFileNameWithoutExtension(uploadFile.PostedFile.FileName);
                    file.Extension = Path.GetExtension(uploadFile.PostedFile.FileName).Replace(".", "").Substring(0, 4);
                    file.FileName = Guid.NewGuid();

                    string fileSavePath = Server.MapPath("") + "\\Wordfiles\\" + Convert.ToString(file.FileName) + ".upl";
                    uploadFile.PostedFile.SaveAs(fileSavePath);

                    file.ProjectID = po.ID;
                    ie.File.AddObject(file);
                    ie.SaveChanges();

Can someone tell me how to "attach" multiple files and then save them in the folder along with the other data as I posted above?

Cheers

pancake
  • 590
  • 7
  • 24

1 Answers1

0

I believe that HTML 5 has the built-in capability to handle multi-file uploads (where HTML4 does not), but I have not worked with HTML5 yet. With HTML4, you must use an external control (typically either javascript or flash), as there is no built-in mechanism to allow multi-file uploads.

I did write a multi file upload page that works with HTML4 or HTML5 utilizing PLupload (an external control) to perform the file picking. I had to find a generic file handler to interface the control to the .aspx upload page. I think that I found that here.

It took a couple hours to implement, but it's worked great.

Community
  • 1
  • 1
MTAdmin
  • 1,023
  • 3
  • 17
  • 36