I want to access my "My documents" folder from my WinForms ToolStrip menu. I am populating ToolStrip with a XML file.
I am storing Environment.GetFolderPath(Environment.SpecialFolder.MyDocu开发者_StackOverflow中文版ments)
in my XML file. It is throwing an error.
Can anyone please help?.
This is part of my xml file.
<item name="MSPowerpoint" action="%PROGRAMFILES%\Microsoft Office\office11\POWERPNT.exe" parameters="/n"/>
<item name="MyDocuments" action="Environment.GetFolderPath(Environment.SpecialFolder.Personal" parameters=""/>
<item name="" text="-" />
This is the method to start applicatons.
public void startapp(string s)
{
ProcessStartInfo pst = new ProcessStartInfo();
pst.UseShellExecute = true;
pst.FileName = s;
Process.Start(pst);
}
This is the error i am getting.. "The system cannot find the file specified."
You need to find a way to evaluate the path before you start the process: you're getting the error 'cannot find the file specified' because the operating system is being literal and looking for a directory or file called 'Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
' and not the actual directory this represents.
Some kind of encoding might work, so instead of putting Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
in the XML, put in a string representing that value - e.g. '#MYDOCUMENTS' - instead, then when the ToolStrip is created you can extract the values.
// For example:
string fileName = GetFileNameFromXml(); // Or however you get it
if (fileName == "#MYDOCUMENTS")
{
fileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
}
startapp(fileName);
What error you are getting? And seems you have missing
)
in the XML File.
action="Environment.GetFolderPath(Environment.SpecialFolder.Personal"
精彩评论