我正在使用它在现有的共享点位置创建一个文件夹。有没有办法在创建之前检查文件夹是否存在,而不是使用 try/catch 来找出这个方法失败然后假设文件夹存在?我已经检查了 webrequest 方法,但没有这样的检查。
try
{
HttpWebRequest request = (System.Net.HttpWebRequest)HttpWebRequest.Create("https://site.sharepoint.com/files/"+foldername);
request.Credentials = CredentialCache.DefaultCredentials;
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)";
request.Method = "MKCOL";
HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
response.Close();
}
catch (Exception ex)
{
//if this piece fails the folder exists already
}