Check whether a path is valid

前端 未结 12 1897
小蘑菇
小蘑菇 2020-11-27 03:39

I am just wondering: I am looking for a way to validate if a given path is valid. (Note: I do not want to check if a file is existing! I only want to proof the validity

12条回答
  •  时光说笑
    2020-11-27 04:19

    You can try this code:

    try
    {
      Path.GetDirectoryName(myPath);
    }
    catch
    {
      // Path is not valid
    }
    

    I'm not sure it covers all the cases...

提交回复
热议问题