我试图认为一种方法可以使用文件的参数PATH及其文件名创建文件,但是当我遇到问题时,当strPath是错误的文本或存在时,GetObjectByPath(strPath)会引发异常,因此我无法检查null或执行其他操作。
static void createDocumentByPath(string path, string fileName)
{
string[] strPath = path.Split('/');
IFolder rootFolder = session.GetRootFolder();
//session.GetObjectByPath();
IFolder target = rootFolder;
String climbPath = "";
for(int i = 0 ; i < strPath.Length ; i++ )
{
createFolder(target, strPath[i]); // custom method createFolder(IFolder target, String folderName)
climbPath += strPath[i] + "/";
target = session.GetObjectByPath(climbPath) as IFolder;
}
//createFolder(rootFolder, strPath[0]);
//createFolder(getFolder(strPath[0]), strPath[1]);
//createFolder(getFolder(strPath[1]), strPath[2]);
}
那么我如何检查GetObjectByPath(strPath),或者是否有替换的解决方案?