3

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.MyDocuments) 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."

Kiquenet
  • 14,494
  • 35
  • 148
  • 243
Lilly
  • 31
  • 1
  • 4

2 Answers2

4

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);
stuartd
  • 70,509
  • 14
  • 132
  • 163
  • thankyou very much i evaluated Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) in my method.it is perfectly working fine now. – Lilly May 18 '11 at 11:04
0

What error you are getting? And seems you have missing

)

in the XML File.

action="Environment.GetFolderPath(Environment.SpecialFolder.Personal"

Anuraj
  • 18,859
  • 7
  • 53
  • 79