Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

While performing certain task in a console application, i am unable to separate normal folder and hidden ones such as "Forms","FormServerTemplates" etc. I am using SPFolder in the obejct model. I have tried both FolderObject.property.count=21 and FolderObject.item==null, but none of these seems to filter the hidden folders.

Scenario : To copy all folders and files inside root folder of document library. Excluding hidden folders such as "Forms", "FormServerTemplates" etc.

static void traverseFolder(SPFolder fold, string path)
        {

            try
            {

                if (!(fold.Item==null))
                {

                    var Listdir = path + @"\" + fold.Name.ToString();
                    string listpath = Listdir.ToString();
                    if (!Directory.Exists(Listdir))
                        Directory.CreateDirectory(Listdir);


                    foreach (SPFolder subFold in fold.SubFolders)
                    {
                        if (!(subFold.Item==null))
                            traverseFolder(subFold, listpath);
                    }

                    foreach (SPFile file in fold.Files)
                    {
                        byte[] binFile = file.OpenBinary();

                        System.IO.FileStream fstream =

                        System.IO.File.Create(listpath + "\\" + file.Name);

                        fstream.Write(binFile, 0, binFile.Length);

                        //Console.WriteLine(file.Name);
                    }

                }      //Console.WriteLine(item.File.Name);
            }

            catch (Exception ex)
            {
                EventLog myException = new EventLog("");
                myException.Source = "SiteCol File Copy Exception";
                myException.WriteEntry("Error in copying " + ex.Message,EventLogEntryType.Error);
            }


        }

Is there any other way to separate?

Thanks

share|improve this question
    
I am just curious, SPFolder.Item==null condition usually filters out forms and related folders, it definitely filters out "Forms" because I used it several times, for which folder the condition is failing? –  Diptarag Nov 28 '12 at 7:46
    
@Diptarag: If i use the condition if (!(fold.Item==null)) then it will not go inside the if condition. Therefore no folder or item within the folder would be traversed. –  Thomas Mathew Nov 28 '12 at 8:45
    
Let me get the scenario you want to traverse the "Forms" (and similar folder) and also normal user created folders but logic for handling those would be different? Why cant you use if-else? If you state your requirement and sample code that will be really helpful. –  Diptarag Nov 28 '12 at 8:50
    
@Diptarag: I have added the scenario as well as the code. I tried if-else, but that didnt work. –  Thomas Mathew Nov 28 '12 at 8:58
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.