开发者

What exception would be raised regarding moving directories and permission issues?

I'm utilizing some network share folders as part of my program. I realized that many things could go wrong and am currently contemplating how to handle exceptions properly. I've noticed that the sharing option needs to be checked off, and permissions have to be properly set before I can move, create, or modify files in the networ开发者_StackOverflowk share folder. I'm using the

directory.move()

As files are created and put into the network share folder, my program will take those files and move them to a local directory specified by the user.

My question is, what exception is raised if:

1. the folder does not exist? I think that's FilenotfoundException

2. if the permissions were not set (cannot access folder). Is that an IO exception? or DirectoryNotFoundException? Or just plain Exception?

Thank you!


Quick Answer

  1. If you try to move a directory that does not exist, or a create a file in a directory that does not exist, you will get a DirectoryNotFoundException.

  2. If the caller does not have permissions, or you attempt to create a file in a path that is read-only, you will get an UnauthorizedAccessException.

Teach Someone To Fish...

You can find this information through

Documentation

See the Exceptions heading for each of the methods you're trying to use.

  • File.Create
  • Directory.Move
  • Etc. (replace the query with the method you are interested in)

Experimentation

  1. To see what happens when the directory doesn't exist, try to move, create, or modify files in C:\hsdfkl or \\yourserver\hsdfkl. Note: I chose that directory name randomly as it is unlikely to exist; if hsdfkl actually does exist, try hsdfkl1.

  2. To see what happens when it exists but you don't have permissions, since you say you don't have admin privileges, try manipulating C:\.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜