我正在使用它在現有的共享點位置創建一個文件夾。有沒有辦法在創建之前檢查文件夾是否存在,而不是使用try/catch來判斷此方法失敗,然後假定該文件夾存在? 我已經檢查了webrequest方法,但沒有這樣的支票。檢查文件夾是否存在c#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
}
可你只是提出一個要求通過'HttpWebRequest'文件夾,看看是否存在(或得到404 )? –