i am uploading 2 files say a.pdf and b.pdf and i am clicking on update button.I can see only a.pdf into agreement folder.It does not upload b.pdf.My VS version is below 4.0,so i used below code.
During debugging.i found that it is going through the loop but both times it takes a.pdf and skipping b.pdf as i selected both.
Source code:
<tr>
<td class="style11">
Reply recieved date<br />
<asp:TextBox ID="TextBox1" Width="207" class="datepicker" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ValidationGroup="valBtoA"
ControlToValidate="txtrecdate" runat="server" ForeColor="red" ErrorMessage="reply date!!"></asp:RequiredFieldValidator>
</td>
<td class="style3">
Agreement
<asp:RadioButton ID="RadioButton1" GroupName="agree" AutoPostBack="true" OnCheckedChanged="enablefileuploader"
runat="server" />
Yes
<asp:RadioButton ID="RadioButton2" GroupName="agree" AutoPostBack="true" OnCheckedChanged="disablefileuploader"
runat="server" />
No <a id="a1" target="_blank" runat="server">
<asp:Label ID="Label1" ForeColor="blue" runat="server"></asp:Label>
</a>
<br />
</td>
</tr>
<tr>
<asp:FileUpload ID="FileUpload2" runat="server" accept=".pdf,.PDF" AllowMultiple="true" />
<asp:Label ID="Label2" runat="server" ForeColor="red"></asp:Label>
</td>
<td class="style12">
Comment2<br />
<asp:TextBox ID="TextBox2" TextMode="MultiLine" Width="207" runat="server"></asp:TextBox>
</td>
</tr>
Code behind:
protected void btnupdate_Click(object sender, EventArgs e)//work
{
string x = Request.QueryString["pid"];
string queryStr = "", rrdate = "", compltdate = "", filename = "", agreement = "", lspdate = "", email2 = "", email3 = "", reason = "";
MySqlConnection connect = null;
MySqlTransaction transaction;
string connStr = ConfigurationManager.ConnectionStrings["BarterConnectionString"].ToString();
connect = new MySqlConnection(connStr);
connect.Open();
if (rbyes.Checked)
{
if (FileUpload1.HasFile)
{
string FileName = System.IO.Path.GetFileName(FileUpload1.FileName);
HttpFileCollection uploadedFiles = Request.Files;
lblfileupmsg.Text = string.Empty;
for (int i = 0; i < uploadedFiles.Count; i++)
{
HttpPostedFile userPostedFile = uploadedFiles[i];
try
{
if (userPostedFile.ContentLength > 0)
{
lblfileupmsg.Text += "<u>File #" + (i + 1) + "</u><br>";
lblfileupmsg.Text += "File Content Type: " + userPostedFile.ContentType + "<br>";
lblfileupmsg.Text += "File Size: " + userPostedFile.ContentLength + "kb<br>";
lblfileupmsg.Text += "File Name: " + userPostedFile.FileName + "<br>";
userPostedFile.SaveAs(Server.MapPath("~/Agreements/" + FileName));
lblfileupmsg.Text += "Location where saved: " + FileName + "~/Agreements/" + Path.GetFileName(userPostedFile.FileName) + "<p>";
}
}
catch (Exception Ex)
{
lblfileupmsg.Text += "Error: <br>" + Ex.Message;
}
}
}
else
{
filename = ViewState["filename"].ToString();
if (filename == "")
{
lblfileupmsg.Text = "Please Upload Agreement file!!!";
return;
}
agreement = "1";
}
}
}