BOEING39
asked on
MULTI FILE UPLOAD
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.
{
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(fpa th))
{
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(fpa th))
{
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,D ates) values('" + fname + "','" + spath + "','" + txtSubject1 + "','" + Ship1 + "','" + Sta1 + "','" + DateTime.Now + "')";
sqlcon.Open();
sqlcmd = new SqlCommand(query, sqlcon);
sqlcmd.CommandType = CommandType.Text;
sqlcmd.ExecuteNonQuery();
sqlcon.Close();
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();
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(fpa
{
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(fpa
{
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,
sqlcon.Open();
sqlcmd = new SqlCommand(query, sqlcon);
sqlcmd.CommandType = CommandType.Text;
sqlcmd.ExecuteNonQuery();
sqlcon.Close();
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Lack of response.
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.