4 Replies - 2341 Views - Last Post: 26 May 2012 - 07:53 AM Rate Topic: -----

#1 spex   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-April 12

Remove filename extension

Posted 26 May 2012 - 05:31 AM

I've made a simple media player using wpf where I add files to a listbox which serves as the source for the mediaelement. Using "Path.GetFileNameWithoutExtension" I've tried to remove the filename extension and the path so that only the filename is shown in the listbox and it does give me the desired result except that the listbox items won't play in the mediaelement.

                System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
                ofd.Multiselect = true;
                if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    foreach (string file in ofd.FileNames)
                    {
                        FileInfo fileName = new FileInfo(System.IO.Path.GetFileNameWithoutExtension(file));                       
                        listBox.Items.Add(fileName);
                    }
                }



Is This A Good Question/Topic? 0
  • +

Replies To: Remove filename extension

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6537
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Remove filename extension

Posted 26 May 2012 - 07:35 AM

You stripped the path down to it no longer being a path, and now your non-path isn't accepted as a path to a song. That's rather a 'duh' circumstance.

So what's your question?
Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6537
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Remove filename extension

Posted 26 May 2012 - 07:41 AM

Maybe this will help.

Listboxes take collectins of objects, not just strings.
So make a class for your song information. It can have properties for Title, Path, Cover Art, Rating, whatever you want.

The listbox wants to show the string or text of an object. So you override .ToString() to provide just the song title.

When a new item is selected from the listbox, use the Path property of the object for your MediaElement.


Please take a try at coding a solution now that you have been given a direction to research. Once you have updated your code if you are still having issues please post in this thread rather than starting a new one.
Was This Post Helpful? 0
  • +
  • -

#4 spex   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-April 12

Re: Remove filename extension

Posted 26 May 2012 - 07:47 AM

View PosttlhIn`toq, on 26 May 2012 - 07:35 AM, said:

You stripped the path down to it no longer being a path, and now your non-path isn't accepted as a path to a song. That's rather a 'duh' circumstance.

So what's your question?


My question is how I can add files to the listbox without the path and filename extension showing up in the listbox. I only want the name of the file to be shown as an item in listbox. If the code I provided is compiled it just shows what I want the listbox items to look like in the listbox.
Was This Post Helpful? 0
  • +
  • -

#5 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6537
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Remove filename extension

Posted 26 May 2012 - 07:53 AM

We must have been typing our responses at the same time.
Look up. See my post #3.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1