Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. getfilename

getfilename

Scheduled Pinned Locked Moved C#
tutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kennyhibs
    wrote on last edited by
    #1

    Hi i have a simple window form with a listbox that plays a highlighted mp3, works great if i add the mp3 to the project bin, however when i try and put a path in for mp3 for example f:\mp3\song.mp3 it says it "cant play file " if i put a copy of the mp3 (song.mp3) in the project bin but leave the path as f:\mp3\song.mp3 then it plays fine so i'm guessing it is defaulting to the project bin to get filename, what am i missing? code: private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { dsAudioPlayer1.FileName = Path.GetFileName(listBox1.SelectedItem.ToString ()); kenny

    L OriginalGriffO 2 Replies Last reply
    0
    • K kennyhibs

      Hi i have a simple window form with a listbox that plays a highlighted mp3, works great if i add the mp3 to the project bin, however when i try and put a path in for mp3 for example f:\mp3\song.mp3 it says it "cant play file " if i put a copy of the mp3 (song.mp3) in the project bin but leave the path as f:\mp3\song.mp3 then it plays fine so i'm guessing it is defaulting to the project bin to get filename, what am i missing? code: private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { dsAudioPlayer1.FileName = Path.GetFileName(listBox1.SelectedItem.ToString ()); kenny

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      kennyhibs wrote:

      Path.GetFileName

      First guess is that you are only getting the filename and not the full path to the file. Try Path.GetFullPath instead.

      Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Individuality is fine, as long as we do it together - F. Burns Help humanity, join the CodeProject grid computing team here

      K 1 Reply Last reply
      0
      • K kennyhibs

        Hi i have a simple window form with a listbox that plays a highlighted mp3, works great if i add the mp3 to the project bin, however when i try and put a path in for mp3 for example f:\mp3\song.mp3 it says it "cant play file " if i put a copy of the mp3 (song.mp3) in the project bin but leave the path as f:\mp3\song.mp3 then it plays fine so i'm guessing it is defaulting to the project bin to get filename, what am i missing? code: private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { dsAudioPlayer1.FileName = Path.GetFileName(listBox1.SelectedItem.ToString ()); kenny

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        GetFileName returns the name of the file: "song.mp3" - i.e. without the path. If you have this in the current directory (as in the case of the project directory) then it can find it. Give it the whole pathed file name and you should be fine. Try

        if (File.Exists(listBox1.SelectedItem.ToString())
        {
        dsAudioPlayer1....
        }
        else
        {
        MessageBox.Show("Cannot find \"" + listBox1.SelectedItem.ToString() + "\"");
        }

        No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        1 Reply Last reply
        0
        • L Lost User

          kennyhibs wrote:

          Path.GetFileName

          First guess is that you are only getting the filename and not the full path to the file. Try Path.GetFullPath instead.

          Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Individuality is fine, as long as we do it together - F. Burns Help humanity, join the CodeProject grid computing team here

          K Offline
          K Offline
          kennyhibs
          wrote on last edited by
          #4

          Thanks for that it was exactly what was wrong, i was trying to get the mp3 to play the filename but was taking out the full path to the file so it couldn't find it :-D kenny

          L 1 Reply Last reply
          0
          • K kennyhibs

            Thanks for that it was exactly what was wrong, i was trying to get the mp3 to play the filename but was taking out the full path to the file so it couldn't find it :-D kenny

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Glad to help

            Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Individuality is fine, as long as we do it together - F. Burns Help humanity, join the CodeProject grid computing team here

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups