Solved

MULTI FILE UPLOAD

Posted on 2013-11-10
6
95 Views
Last Modified: 2014-10-01
Please find the attached C# code as a reference.   The Upload function is working for "fileUpload1"; however, not for "fileUpload2" .   When I submit with "fileUpload2" containing the file only #1 goes into the data base.    


protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (fileUpload1.HasFile)
        {
           
            fname = fileUpload1.FileName;
            spath = @"~\Uploaded\" + fileUpload1.FileName;
            fpath = Server.MapPath("~/Uploaded");
            fpath = fpath + @"\" + fileUpload1.FileName;            
            txtSubject1 = txtSubject.Text;
            Ship1 = Ship.Text;
            Sta1 = Sta.Text;
             
            if (System.IO.File.Exists(fpath))
            {
                Label1.Text = "File Name already exists!";
                return;
            }
            else
            {
                fileUpload1.SaveAs(fpath);
            }
            //Store details in the SQL Server table
            StoreDetails();
            txtSubject.Text = "";
            Ship.Text = "";
            Sta.Text = "";
            
        }
        else
        {
            Label1.Text="Please select file!";
        }


        if (fileUpload2.HasFile)
        {

            fname = fileUpload2.FileName;
            spath = @"~\Uploaded\" + fileUpload2.FileName;
            fpath = Server.MapPath("~/Uploaded");
            fpath = fpath + @"\" + fileUpload2.FileName;
            txtSubject1 = txtSubject.Text;
            Ship1 = Ship.Text;
            Sta1 = Sta.Text;

            if (System.IO.File.Exists(fpath))
            {
                Label1.Text = "File Name already exists!";
                return;
            }
            else
            {
                fileUpload2.SaveAs(fpath);
            }
            //Store details in the SQL Server table
            StoreDetails();
            txtSubject.Text = "";
            Ship.Text = "";
            Sta.Text = "";

        }
        else
        {
            Label2.Text = "Please select file!";
        }


    }
    void StoreDetails()
 {
     String query;
     query = "insert into fileDet(fname,fpath,desc1,Ship,Sta,Dates) values('" + fname + "','" + spath + "','" + txtSubject1 + "','" + Ship1 + "','" + Sta1 + "','" + DateTime.Now + "')";
     sqlcon.Open();
     sqlcmd = new SqlCommand(query, sqlcon);
     sqlcmd.CommandType = CommandType.Text;
     sqlcmd.ExecuteNonQuery();
     sqlcon.Close();

Open in new window

protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (fileUpload1.HasFile)
        {
           
            fname = fileUpload1.FileName;
            spath = @"~\Uploaded\" + fileUpload1.FileName;
            fpath = Server.MapPath("~/Uploaded");
            fpath = fpath + @"\" + fileUpload1.FileName;            
            txtSubject1 = txtSubject.Text;
            Ship1 = Ship.Text;
            Sta1 = Sta.Text;
             
            if (System.IO.File.Exists(fpath))
            {
                Label1.Text = "File Name already exists!";
                return;
            }
            else
            {
                fileUpload1.SaveAs(fpath);
            }
            //Store details in the SQL Server table
            StoreDetails();
            txtSubject.Text = "";
            Ship.Text = "";
            Sta.Text = "";
           
        }
        else
        {
            Label1.Text="Please select file!";
        }


        if (fileUpload2.HasFile)
        {

            fname = fileUpload2.FileName;
            spath = @"~\Uploaded\" + fileUpload2.FileName;
            fpath = Server.MapPath("~/Uploaded");
            fpath = fpath + @"\" + fileUpload2.FileName;
            txtSubject1 = txtSubject.Text;
            Ship1 = Ship.Text;
            Sta1 = Sta.Text;

            if (System.IO.File.Exists(fpath))
            {
                Label1.Text = "File Name already exists!";
                return;
            }
            else
            {
                fileUpload2.SaveAs(fpath);
            }
            //Store details in the SQL Server table
            StoreDetails();
            txtSubject.Text = "";
            Ship.Text = "";
            Sta.Text = "";

        }
        else
        {
            Label2.Text = "Please select file!";
        }


    }
    void StoreDetails()
 {
     String query;
     query = "insert into fileDet(fname,fpath,desc1,Ship,Sta,Dates) values('" + fname + "','" + spath + "','" + txtSubject1 + "','" + Ship1 + "','" + Sta1 + "','" + DateTime.Now + "')";
     sqlcon.Open();
     sqlcmd = new SqlCommand(query, sqlcon);
     sqlcmd.CommandType = CommandType.Text;
     sqlcmd.ExecuteNonQuery();
     sqlcon.Close();
0
Comment
Question by:BOEING39
  • 3
6 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 39637716
Have you tried stepping through the code to see when/if an error occurs?

Are any of your database fields mandatory as you are setting several field to empty string after calling StoreDetails() for the first upload file :

txtSubject.Text = "";
            Ship.Text = "";
            Sta.Text = "";

so maybe you are getting an error when you call StoreDetails() for the 2nd file upload because these fields are blank.
0
 

Author Comment

by:BOEING39
ID: 39637753
When I attach a file to fleUpload1 the attached file is Uploaded to the "Uploads" folder along with the corresponding text being entered into the respective data base.  

When I attach a file to "fileUpload2" the same text information should go to the data base and the fileUpload2 attachment should be sent to the Uploads folder.  This is not occurring.
0
 

Accepted Solution

by:
BOEING39 earned 0 total points
ID: 39679662
No responses further responses.  Please close question.
0
 

Author Closing Comment

by:BOEING39
ID: 40354158
Lack of response.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now