Last post Dec 29, 2016 05:37 AM by Zhi Lv - MSFT
Dec 28, 2016 11:58 AM|Capricon User|LINK
<div class="post-text" itemprop="text">
I have file upload and upload link button and submit button .. so when i select file and click on upload then file name display in label and when i again click on browse file and select file and click on upload then file name again save in label so means
multiple file name display in label i.e.
.. and so on ..
now i try to save these files in database with different record means if these files save in database table then look like this
ID DocumentName DocumentPath
1 abc.docx /downloads/abc.docx
2 def.docx /files/def.docx
Index was outside the bounds of the array.
and how i insert also document path
any help ?
Dec 29, 2016 05:37 AM|Zhi Lv - MSFT|LINK
Hi Bakhtawar Ashiq,
According to your description, I suggest you could refer to the following code to display the file name and insert them into database.
<asp:FileUpload ID="fileUpEx" runat="server" AllowMultiple="true" /><br />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label><br />
<asp:Button ID="btnAddFile" runat="server" OnClick="btnAddFile_Click" Text="Add file name to Label" /><br />
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Insert file into database" /><br />
'use a list to store the selected file name. Protected Shared itemList As List(Of String) = New List(Of String)
Protected Sub btnAddFile_Click(sender As Object, e As EventArgs)
If fileUpEx.HasFiles Then
For Each uploadedfile As HttpPostedFile In fileUpEx.PostedFiles
Next 'When display the file name, use Join method to join the file name and add line feed
Label1.Text = String.Join("<br/>", itemList)
Protected Sub btnSubmit_Click(sender As Object, e As EventArgs) 'loop through the list and insert the file name into database.
For Each filepath As String In itemList
//insert into database