Question

I want to check if a folder exists in sharepoint. But it could be any folder hosted in IIS.

Does Directory.Exists work? If not...

I found this method below, but it only creates the folder, no check to see if it already exists or not, does anyone have some working code to check if the folder exists?:

 private bool CreateFolder(string folderURL)

        {

            try

            {

                WebRequest request = WebRequest.Create(folderURL);

                request.Credentials = m_credentials;

                request.Method = "MKCOL";

                WebResponse response = request.GetResponse();

                response.Close();

                return true;

            }

            catch (WebException)

            {

                return false;

            }

        }
Was it helpful?

Solution

No Directory.Exists does not work for URLs. As far as detecting the existance of the folder a GET, HEAD or PROPFIND request ought to be able to determine that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top