Create a new folder in a sharepoint list - InfoPath Dev
in

InfoPath Dev

Create a new folder in a sharepoint list

Last post 05-25-2010 01:26 PM by mgarant. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 05-25-2010 12:31 PM

    Create a new folder in a sharepoint list

    Hello there,

     I'm trying to create a new folder in my sharepoint list on submit event. I use the Microsoft.Sharepoint assembly to do it. There is the code i came with :

    ----------------------------------------------------------------------------------------------------

    SPSite oSiteCollection = new SPSite("http://srvspsdev/");

    SPWeb oWebsiteSrc = oSiteCollection.AllWebs[""];

    SPList oList = oWebsiteSrc.Lists["testPOR"];

    oWebsiteSrc.Site.WebApplication.FormDigestSettings.Enabled = false;

    oList.Folders.Add("/testPOR/" + root.SelectSingleNode("/my:myFields/my:Approvals/my:Departments", NamespaceManager).Value, SPFileSystemObjectType.Folder, formName);

    oList.Update();

    oWebsiteSrc.Site.WebApplication.FormDigestSettings.Enabled = true;

    --------------------------------------------------------------------------------------------------------

    But when a submit my form, it just don't create anything... I've been searching for some other way to do this but couldn't find any... Any help would be appreciated!!

     Thank in advance!

  • 05-25-2010 01:26 PM In reply to

    Re: Create a new folder in a sharepoint list

    Well i've finally managed to do it!

    Here's how to do it, for those who would need it.

     ---------------------------------------------------------------------------------------------

    SPSite oSiteCollection = new SPSite("Your site collection");

    SPWeb oWebsiteSrc = oSiteCollection.OpenWeb();

    SPList oList = oWebsiteSrc.Lists["The name of your list"];

    oWebsiteSrc.Site.WebApplication.FormDigestSettings.Enabled = false;SPFolder folder = oList.RootFolder.SubFolders[root.SelectSingleNode("/my:myFields/my:Approvals/my:Departments", NamespaceManager).Value].SubFolders.Add(formName);

    SPListItem item = folder.Item;

    item.Update();

    oWebsiteSrc.Site.WebApplication.FormDigestSettings.Enabled = true;

    ----------------------------------------------------------------------------------------------------------------------------------------

    Note that in this line (SPFolder folder = oList.RootFolder.SubFolders[root.SelectSingleNode("/my:myFields/my:Approvals/my:Departments", NamespaceManager).Value].SubFolders.Add(formName);)

    if you want to create a folder directly in the list (not in a folder of the list), you can scrap "SubFolders[root.SelectSingleNode("/my:myFields/my:Approvals/my:Departments", NamespaceManager).Value]".

     

    I hope it is clear for everyone!

     

Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.