troubleshooting Question

SharePoint folder.exist

Avatar of Isaac
IsaacFlag for United States of America asked on
Microsoft SharePoint.NET ProgrammingC#
6 Comments2 Solutions465 ViewsLast Modified:
Something weird is happening when I try to see if a folder exist in a document library.
When CheckFolderExist() is called, it's always false no matter what ("NO FOLDER"), but when I get to the if statement (if (folderExist){}), it comes out true all the time no matter what.
Can somebody please explain? Does my code need to be modified.  It's been driving me crazy for the past 2 days.

using (SPSite mySite = new SPSite("http://landis/"))
        {
            using (SPWeb myWeb = mySite.OpenWeb())
            {                

             }
         }

string caseFolder = txtCaseNumber.Text.ToString();
.
.
bool folderExist = CheckFolderExists(myWeb, caseFolder);

 if (folderExist)
                        {
                            msg.Text += "Folder Exist<br />";
                        }
                        else
                        {
                            msg.Text += "None<br />";
                        }


private bool CheckFolderExists(SPWeb wb, string fldr)
    {
        try
        {
            SPFolder folder = wb.GetFolder(fldr);
            if (!folder.Exists)
            {
                msg.Text += "NO FOLDER<br />";
                return false;
            }
            else
            {
                msg.Text += "FOLDER EXISTS<br />";
                return folder.Exists;
            }
        }
        catch
        {
            return false;
        }
    }

Open in new window

ASKER CERTIFIED SOLUTION
Member_6283346

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros