locked
Insert document name & document path in vb.net RRS feed

  • Question

  • User639567535 posted

    <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.

    abc.docx
    def.docx

    .. 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 ?

    </div>

    Wednesday, December 28, 2016 11:58 AM

Answers

  • User-271186128 posted

    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 />

    Code behind:

        '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 itemList.Add(uploadedfile.FileName) Next
    'When display the file name, use Join method to join the file name and add line feed Label1.Text = String.Join("<br/>", itemList) End If End Sub 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 Next End Sub

    Best regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 29, 2016 5:37 AM