none
SPFolder vs SPList

    Question

  • What is the difference between an SPFolder and an SPList, particularly in reference to a Document Library.

    I'm trying to learn how to add a new, programmatically created, SPFile to a Document Library, but seem to be running into this SPFolder concept.

    Thursday, February 17, 2011 2:52 AM

Answers

  • Hi,

    >SPFolder and an SPList

    SPFolder: This class will give you all the folders / subfolders from a document library.

    SPList: This class will give the name of document library /list.

    EX Code:

    using (SPSite mySite = new SPSite(weburl))
             {
               using (SPWeb myWeb = mySite.OpenWeb())
             {

                SPList list = myWeb.Lists["Document library title"];

               SPFolder folderInstance = list.RootFolder.SubFolders[folderUrl]; //specific folder

               SPFolder folderInstance = list.Folders; ///Give all folders

         }
    }

    Hope It could help


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"
    • Marked as answer by sdfsda Friday, February 18, 2011 7:45 PM
    Thursday, February 17, 2011 4:33 AM
  • In addition with Hemendra...

    //can create file programatically or get file by browse

    Stream fStream = File1.PostedFile.InputStream;
    byte[] contents = new byte[fStream.Length];

    fStream.Read(contents, 0, (int)fStream.Length);
    fStream.Close();

    EnsureParentFolder(myWeb , destUrl);

    myWeb.Files.Add(destUrl, contents);


    thanksArup MCTS - SharePoint

    Play Sudoku Online
    • Marked as answer by sdfsda Friday, February 18, 2011 7:45 PM
    Thursday, February 17, 2011 9:36 AM

All replies

  • Hi,

    >SPFolder and an SPList

    SPFolder: This class will give you all the folders / subfolders from a document library.

    SPList: This class will give the name of document library /list.

    EX Code:

    using (SPSite mySite = new SPSite(weburl))
             {
               using (SPWeb myWeb = mySite.OpenWeb())
             {

                SPList list = myWeb.Lists["Document library title"];

               SPFolder folderInstance = list.RootFolder.SubFolders[folderUrl]; //specific folder

               SPFolder folderInstance = list.Folders; ///Give all folders

         }
    }

    Hope It could help


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"
    • Marked as answer by sdfsda Friday, February 18, 2011 7:45 PM
    Thursday, February 17, 2011 4:33 AM
  • In addition with Hemendra...

    //can create file programatically or get file by browse

    Stream fStream = File1.PostedFile.InputStream;
    byte[] contents = new byte[fStream.Length];

    fStream.Read(contents, 0, (int)fStream.Length);
    fStream.Close();

    EnsureParentFolder(myWeb , destUrl);

    myWeb.Files.Add(destUrl, contents);


    thanksArup MCTS - SharePoint

    Play Sudoku Online
    • Marked as answer by sdfsda Friday, February 18, 2011 7:45 PM
    Thursday, February 17, 2011 9:36 AM