"System.IO.FileSystemInfo.FullPath" not available due to security level error in C #

I have a C # program as shown below. But this fails. Error - "System.IO.FileSystemInfo.FullPath" not available due to security level. And FullPath is underlined in blue.

protected void Main(string[] args)
{
    DirectoryInfo parent = new DirectoryInfo(@"C:\Users\dell\Desktop\rename");
    foreach (DirectoryInfo child in parent.GetDirectories())
    {
        string newName = child.FullPath.Replace('_', '-');

        if (newName != child.FullPath)
        {
            child.MoveTo(newName);
        }
    }
}

      

+3


source to share


2 answers


The property you are looking for is called FullName

, not FullPath

:



static void Main()
{
    DirectoryInfo parent = new DirectoryInfo(@"C:\Users\dell\Desktop\rename");
    foreach (DirectoryInfo child in parent.GetDirectories())
    {
        string newName = child.FullName.Replace('_', '-');

        if (newName != child.FullName)
        {
            child.MoveTo(newName);
        }
    }
}

      

+6


source


Try FullName instead of FullPath:

http://msdn.microsoft.com/fr-fr/library/8s2fzb02.aspx



this should work for you :)

0


source







All Articles