Ashwin_shastry
asked on
process argument contains space in filename
Hi everyone:
I want to play a song by clicking a button. For example if i want to play song using windows media player here is the code....On click of play button
Process myProcess = new Process();
myProcess.StartInfo.FileNa me ="wmplayer";
myProcess.StartInfo.Argume nts = @"C:\bin\pleaseforgiveme.m p3";
myProcess.StartInfo.Window Style = ProcessWindowStyle.Normal;
myProcess.Start();
This works fine. The problem i am having right now is if the file name is C:\bin\Please forgive me.mp3 i.e if it has whitespaces in the file (space b/w please forgive me) it does n't play the file. Or if it has underscore(_) in file name like please_forgive_me it does not play file. It throws exception. Could any of you help me in this ?
Thanks and with regards
Ashwin
I want to play a song by clicking a button. For example if i want to play song using windows media player here is the code....On click of play button
Process myProcess = new Process();
myProcess.StartInfo.FileNa
myProcess.StartInfo.Argume
myProcess.StartInfo.Window
myProcess.Start();
This works fine. The problem i am having right now is if the file name is C:\bin\Please forgive me.mp3 i.e if it has whitespaces in the file (space b/w please forgive me) it does n't play the file. Or if it has underscore(_) in file name like please_forgive_me it does not play file. It throws exception. Could any of you help me in this ?
Thanks and with regards
Ashwin
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Did this work? Please close out if it did
ASKER
Good ...It works...Thank you.
One approach is to explicitly escape special characters within the string with \
For example,
void Button2Click(object sender, System.EventArgs e)
{
try
{
Process myProcess = new Process();
myProcess.StartInfo.FileNa
myProcess.StartInfo.Argume
MessageBox.Show(myProcess.
myProcess.StartInfo.Window
myProcess.Start();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message
}
}
This works just fine and plays the song.