OpenFileDialog Multiple files GET Name, Extension and path

Posted on 2011-10-16
Last Modified: 2012-05-12
I have a simple question.

I have set the OpenfileDialog.Multiple = true

Now I need to iterate through the Selected files and save the File NAme, Extension and full Path to a table.

Please see code below.

IN the following approach : I can iterate and get only the Path/File Name or extansion.

How can I iterate and get all the three fields.
        Dim file As String
        If OpenFileDialog1.ShowDialog = DialogResult.OK Then
            For Each file In OpenFileDialog1.FileNames

                ds.Tables("Temp").Rows.Add(file,(File Name),(Extension))

            GridControl1.DataSource = ds.Tables("Temp")
        End If

Open in new window

Question by:isaackhazi
    LVL 85

    Accepted Solution

    Try something like:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If OpenFileDialog1.ShowDialog = DialogResult.OK Then
                For Each file As String In OpenFileDialog1.FileNames
                    ds.Tables("Temp").Rows.Add(New Object() {file, System.IO.Path.GetFileNameWithoutExtension(file), System.IO.Path.GetExtension(file)})
                GridControl1.DataSource = ds.Tables("Temp")
            End If
        End Sub

    Open in new window

    LVL 9

    Assisted Solution


    Imports System.IO

    and add this line

    ds.Tables("Temp").Rows.Add(Path.GetFullPath(file), Path.GetFileName(file), Path.GetExtension(file))
    LVL 1

    Assisted Solution

    Use this:-

     ds.Tables("Temp").Rows.Add(file, IO.Path.GetFileNameWithoutExtension(file), IO.Path.GetExtension(file))

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now