Trouble when creating directory

Hi guys,

I need my application to get the startup directory and check if subDir X exists, otherwise I create a new one.

I am trying the following code, but getting error: (I am working on server)

public void createDirectory(string name, bool hidden)

{

if (!Directory.Exists(name))

{

Directory.CreateDirectory(name);

};

DirectoryInfo dir = new DirectoryInfo(name);

if (hidden)

dir.Attributes |= FileAttributes.Hidden;

else

dir.Attributes &= ~FileAttributes.Hidden;

} // end of reateDirectory

Error detail:

Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Could anybody tell me how to deal with it

Thanks in advance,

Aldo.




Answer this question

Trouble when creating directory

  • thaoula

    the exception says taht you|your code do not have permissions to create Folder.

    start application from local HDD not from network share. this could solve the problem.

    check if account in which you start app has permissions to create folder there

    hope this helps



  • CarolJ

    right click on folder where you want to create subfolder and select Sharing and Security...

    click on security tab and add your user and give him Modify, Write permissions

    hope this helps



  • DaveOnSEN

    Hi Galin,

    thanks for your answer.

    Could you tell me how to change to a specified directory

    I want to tell my application to start looking into directory "X"



  • Trouble when creating directory