Click here to Skip to main content
15,907,497 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi all,

I got stuck when I tried to play a wav file in my c# smart device application.
The exception is "Could not find a part of the path '\C:\Users\Desktop\test.wav'."
I've tried with copying the wav file to emulator's "my Document\my music" and changed
soundLocation according to that path,but doesn't work. And also I copied wav file into myProject's debug folder..no change.

Plz help.

my code is
C#
{
    System.Media.SoundPlayer player = new System.Media.SoundPlayer();
    player.SoundLocation = @"C:\Users\Desktop\test.wav";
    player.Play();
}

Thanks.
Posted
Updated 19-Sep-12 4:25am
v2
Comments
[no name] 19-Sep-12 10:45am    
Move your file to another Drive, may be helps you!
Ran 2 19-Sep-12 10:48am    
Thanks Meysam.
I tried..but doesn't work.

use this address man...
"C:\\Users\\"+Environment.UserName+"\\Desktop\\test.wav"
 
Share this answer
 
Comments
Er. Tushar Srivastava 19-Sep-12 11:56am    
I too forgot that the real location of desktop is C:\Users\Username\Desktop" and not C:\Users\Desktop ....... Very well done sir... but I guess he has tried other locations also....
First of all,Thank you all for response..

have somebody of you saw that there is a " \ " sign at the beginning of the exception.. what does that mean??
 
Share this answer
 
Hi Friend,
There is a simple mistake in the url you are giving to the player object.
As you know anything after a forward slash "\" is considered as an escape character and so, the url as interpreted by system is wrong.
The correct systax would be.

C#
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = "C:\\Users\\Desktop\\test.wav";
player.Play();


Have a look at "\\" instead of "\"
Hope it will help you.

Regards
Tushar Srivastava
 
Share this answer
 
Comments
[no name] 19-Sep-12 11:35am    
"player.SoundLocation = @"C:\Users\Desktop\test.wav";", is perfectly fine and is not the problem. The @ unescapes the \.
Er. Tushar Srivastava 19-Sep-12 11:40am    
Yes you are right....... Sorry for that.... and thank you for pointing it out..
Er. Tushar Srivastava 19-Sep-12 11:42am    
I have tested the codes in my system and it is working perfectly...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900