Windows Develop Bookmark and Share   
 index > Windows Forms General > Path related query
 

Path related query

Hi,
I am plaiyng a wav file through the following code...
SoundPlayer player = new SoundPlayer();
string path = "C:\\windows\\media\\ringin.wav";
player.SoundLocation = path; //Set the path
player.Play();

Now, instead of "C:\\windows\\media\\ringin.wav" path , I have created a Media folder in my Project Directory where I have copied this wav file. And in the code I want to use path of the Media folder of my Project .
I tried "\media.." or @"media" but no success.

Can Anybody tell me how I can specify the path in windows application.
Tejaswini Prashant J  Wednesday, September 09, 2009 11:32 AM
Hi,

Try

string path = @"..\..\Media\ringin.wav";

or to use the other sample provided;

string path = System.Environment.CurrentDirectory + @"..\..\Media\file.ext";

Your program is running from E:\Projects\MyProject\Project1.0\WindowsProject\bin\Debug\ but you have created the Media folder at E:\Projects\MyProject\Project1.0\WindowsProject so you need to go up two levels before trying to get to the media folder. The "..\..\" should walk you back up two levels.

However, if this is not the same structure you intend to use when you deploy your app, you would be best to move the media folder and make it the same as the structure you intend of production machines.
Yort  Thursday, September 10, 2009 4:43 AM
string path = System.Environment.CurrentDirectory + @"\Media\file.ext";

See similar recentlyanswered question.
Wole Ogunremi  Wednesday, September 09, 2009 11:57 AM

Hi,

I am getting Path as
E:\Projects\MyProject\Project1.0\WindowsProject\bin\Debug\ \media\ringin.wav ( as I am in debug mode)

Where as this file is located at E:\Projects\MyProject\Project1.0\WindowsProject\ media\ringin.wav

Can I directly get the same psath..or I have to use string operations for it?
Tejaswini Prashant J  Thursday, September 10, 2009 4:31 AM
Hi,

Try

string path = @"..\..\Media\ringin.wav";

or to use the other sample provided;

string path = System.Environment.CurrentDirectory + @"..\..\Media\file.ext";

Your program is running from E:\Projects\MyProject\Project1.0\WindowsProject\bin\Debug\ but you have created the Media folder at E:\Projects\MyProject\Project1.0\WindowsProject so you need to go up two levels before trying to get to the media folder. The "..\..\" should walk you back up two levels.

However, if this is not the same structure you intend to use when you deploy your app, you would be best to move the media folder and make it the same as the structure you intend of production machines.
Yort  Thursday, September 10, 2009 4:43 AM

string path = System.Environment.CurrentDirectory + @"..\..\Media\file.ext";
will concatinate path with ..\..\Media\file.ext ...

Any other way I can do this...?
Tejaswini Prashant J  Monday, September 14, 2009 9:40 AM
Hi,

Have you tested it? The "..\" path takes you back one relative folder. Eg "C:\Windows\Microsoft.NET\..\..\Program Files" is like saying from "C:\Windows\Microsoft.NET" go back 2 folders to ""C:\" and then go to the "Program Files" folder.

Try it first. And if it works, mark Yort's answer.

Regards
Wole
Wole Ogunremi  Monday, September 14, 2009 10:41 AM

If you add the wav file into the project, you can use the relative path like @”…\...\media\file.exe?

If you are not sure the relative path, you can use the Uri.makeRelativeUri method.

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/954346c8-cbe8-448c-80d0-d3fc27796e9c

A similar thread: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/464a4d2a-aaeb-4d07-9863-b8a8002404c1

Best regards,

Ling Wang


Please remember to click “Mark as Answer?on the post that helps you, and to click “Unmark as Answer?if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Thursday, September 17, 2009 8:13 AM

You can use google to search for other answers

Custom Search

More Threads

• ImageList
• RadioButton changes checkstate when form is shown
• Open internal html file located in data directory with WebBrowser?
• problem with For
• ListBox right click that selects item
• picturebox,filestream,memorystream
• ToolStripSplitButton->ToolStripMenuItem checkmark position
• ShortcutsEnabled in TextBox
• Font Serialization GdiCharSet issue
• system.runtime.Interopservices.SEhexception in VB.net