I wanted to view the uploaded files. I am uploading 2 PDF's out of which only 1 PDF is showing when I click on uploaded(view) link. The issue is only viewing the uploaded file
. I am uploading the 2 PDF files in agreement folder
where I can see the uploaded files. But when I click on uploaded(view) link, it displays only 1 PDF file.
Below is my code.
Page load:
ViewState["filename"] = agremtname;
if (dt.Rows[0]["agreement"].ToString() == "0")
{
rbno.Checked = true;
FileUpload1.Enabled = false;
}
else
{
rbyes.Checked = true;
lbluploadmsg.Text = "Uploaded(View)";
agreefile.Attributes["href"] = "~/Agreements/"+ agremtname;
}
Source code:
<tr><td class="style11" >Reply recieved date<br/> <asp:TextBox ID="txtrecdate" Width="207" class="datepicker" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator10"
ValidationGroup="valBtoA" ControlToValidate="txtrecdate" runat="server" ForeColor="red" ErrorMessage="reply date!!"></asp:RequiredFieldValidator>
</td>
<td class="style3">
Agreement
<asp:RadioButton ID="rbyes" GroupName="agree" AutoPostBack="true" OnCheckedChanged="enablefileuploader" runat="server" />
Yes
<asp:RadioButton ID="rbno" GroupName="agree" AutoPostBack="true" OnCheckedChanged="disablefileuploader" runat="server" />
No
<a id="agreefile" target="_blank" runat="server"><asp:Label ID="lbluploadmsg" ForeColor="blue" runat="server" ></asp:Label>
</a>
<br/>
</td>
</tr>
<tr>
<td class="style10"> Agreement<br/>
<%--<asp:TextBox ID="txtagreement" runat="server" Width="119px"></asp:TextBox>--%>
<asp:FileUpload ID="FileUpload1" runat="server" accept=".pdf,.PDF" AllowMultiple="true" />
<asp:Label ID="lblfileupmsg" runat="server" ForeColor="red"></asp:Label>
</td>
<td class="style12">
Comment2<br/>
<asp:TextBox ID="txtcomment2" TextMode="MultiLine" Width="207" runat="server"></asp:TextBox>
</td>
</tr>
Update button code:
if (rbyes.Checked)
{
if (FileUpload1.HasFile)
{
agreement = "1";
filename = Path.GetFileName(FileUpload1.FileName);
string fileLocation = Server.MapPath("~/Agreements/" + filename);
FileUpload1.SaveAs(fileLocation);
}
else {
filename = ViewState["filename"].ToString();
if (filename == "")
{
lblfileupmsg.Text = "Please Upload Agreement file!!!";
return;
}
agreement = "1";
}
}
else if (rbno.Checked)
{
filename = "";
agreement = "0";
}
I know that to view multiple files, I have to use a loop in page load
but I am not getting how to implement it.
You have to take count variable to count the number of files, also you have to save multiple file name in a variable and seperate them using , through logic first.
int Count = 0;
Inside for each loop
agreement = "1";
filename = Path.GetFileName(FileUpload1.FileName);
string fileLocation = Server.MapPath("~/Agreements/" + filename);
FileUpload1.SaveAs(fileLocation);
count++
if (count > 1)
{
string multiplefilename += "," + filename;
}
else if (count == 1)
{
string multiplefilename = filename;
}
While Retrieving files to get view
First split the multiplefilename with ,and save the result in array of string and
string[] Array = recc.MultipleFile.Split(',');
retrieve files then using for loop.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.