How to add folder in picture library programmatically

 
Hi All,
I tried to add folder using below code but getting error of "Missing FileLeaf"
try
                if (properties.List.Title.ToString() == Utility.ListName.Events.ToString())
                    using (SPSite objSite = properties.Site)
                        using (SPWeb objWeb = properties.Web)
                            SPListItem lstEvent = properties.ListItem;
                            string folderName = Convert.ToString(lstEvent["Title"]) + "_" + DateTime.Now.ToShortDateString();
                            if (!string.IsNullOrEmpty(folderName))
                                SPList lstEventPictures = objWeb.Lists.TryGetList(Utility.LibraryName.EventPictures.ToString());
                                if (lstEventPictures != null)
                                    objWeb.AllowUnsafeUpdates = true;
                                    //SPListItemCollection folders = lstEventPictures.Folders;
                                    //folders.Add(lstEventPictures.RootFolder.ServerRelativeUrl 
, SPFileSystemObjectType.Folder , folderName);
                                    ///* create a folder under the path specified
                                    SPListItem folderItem = lstEventPictures.Items.Add(lstEventPictures.RootFolder.ServerRelativeUrl,
SPFileSystemObjectType.Folder , folderName);
                                    ///* set the folder name and update */
                                    //folderItem["Title"] = folderName;
                                    folderItem.Update();
                                    lstEventPictures.Update();
                                    objWeb.AllowUnsafeUpdates = false;
            catch (Exception ex)
                Utility.SPTraceLogError(ex);
Help me to resolve. Thanks in advance.

Hi DK,
You can use below mentioned code to add folder in any of your library. You need to changes little bit code as per your requirement.
/// <summary>
/// Provide utilities methods related to folder management
/// </summary>
public static class SPFolderUtilities
    /// <summary>
    /// Ensures the specified folder exists.
    /// </summary>
    /// <param name="list">The list where to create the folder.</param>
    /// <param name="subFolderPath">The sub folder path.</param>
    /// <returns>
    /// The existing <see cref="SPFolder"/> or a newly created if it did not exists.
    /// </returns>
    public static SPFolder EnsureFolder(SPList list, string subFolderPath)
        Contract.Requires<ArgumentNullException>(list != null);
        Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(subFolderPath));
        if (!IO.SPPathUtilities.IsFileOrFolderNameValid(subFolderPath, true))
            throw new ArgumentException("Invalid characters in the file or folder name", "subFolderPath");
        var folderPaths = subFolderPath.Split('/');
        var currentFolder = list.RootFolder;
        for (int i = 0; i < folderPaths.Length; i++)
            currentFolder = list.ParentWeb.GetFolder(currentFolder.Url); // hacky refresh
            var subFolder = currentFolder.SubFolders.Cast<SPFolder>().FirstOrDefault(f => string.Compare(f.Name, folderPaths[i], true) == 0);
            if (subFolder == null)
                var newFolderItem = list.Items.Add(currentFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder, folderPaths[i]);
                newFolderItem.SystemUpdate();
                subFolder = newFolderItem.Folder;
            currentFolder = subFolder;
        return currentFolder;
And here is the specifc code that you can use for Picture library only
Question
Vote as helpful
0
Vote
yes the code sample provided by you is to create a image library and then to add a folder to it but i'm not sure with the string.empty being passed to list.items.add. i would still recommend to use the solution suggested by me. to check if library exists or
not what you have to do is 
SPSite _MySite = new SPSite("SERVERIP");  
                using (SPWeb currentweb = _MySite.OpenWeb())
SPList imageLib = currentweb.Lists["NewImages]
if( imageLib == null)
Guid listId = currentweb.Lists.Add("NewImages", "Picture Library", SPListTemplateType.PictureLibrary);
 imageLib t = currentweb.Lists[listId];    
SPDocumentLibrary
 _MyDocLibrary =
(SPDocumentLibrary)
imageLib ;
                 SPFolderCollection _MyFolders = _MyWeb.Folders;
                _MyFolders.Add("http://adfsaccount:2222/My%20Images/" + <<subfolderName>> + "/");
                _MyDocLibrary.Update();
I hope this is helpful to you, mark it as Helpful.
If this works, Please mark it as Answered.
Regards,
Dharmendra Singh (MCPD-EA | MCTS)
Blog : http://sharepoint-community.net/profile/DharmendraSingh

Similar Messages

  • HT1849 how to add folder to music library on itunes 11.1

    Can some one please help me how to add a folder to music library. I can see add a file to music library option but not folder option.
    Thanks in Advance

    You should be able to add folders via the File > Add To Library menu option - if I go into that and highlight the folder that I want to add in the pop-up dialogue box, then clicking the Open button at the bottom of the dialogue box adds that folder's content to my library

  • How to add a profile picture to iTunes account in Yosemite?

    How to add a profile picture to iTunes account in Yosemite?

    Hi,
    You need to do the following:
    - Login to System Administrator responsibility
    - Navigate to System > Profile
    - Query the Profile Option Name and the Username (select the username checkbox)
    - Set the profile option value to the user
    - Ask the user to logout and login again
    Thanks,
    Hussein

  • How can add RINGTONE icon to library?help

    how can add RINGTONE icon to library?help

    To analyze anything in LabVIEW you have to be able to access the signal through some sort of DAQ board. Once you have the signal going to a board then you have to have the right driver (packaged code) to be able for LabVIEW to communicate with that device. There are a lot of supported drivers at ni.com/idnet or you can create your own. Check out this site for how LabVIEW interacts with Audio. This other site  has information on using your local sound card with your microphone or speaker input/output to interact with LabVIEW. Hopefully this will get you started in the right direction. Make sure and only add the answered tag to your post only if your question was truly answered and Kudos are always appreciated. Cheers!!
    Grant H.
    National Instruments
    LabVIEW Product Marketing Manager

  • How to add a new Shared Variable programmatically to an existing and deployed library?

    Hi there!
    I am trying to accomplish this on both LabVIEW 8.6 and LabVIEW 2010 and seems like it's not any different in this situation.
    My case: A project has a library with 4 Shared Variables (SVs). The library and the variables are deployed (visible in Distributed System Manager 8.6/2010). I want to add 2 more variables into this library. It is possible to do this manually from Project Explorer window's options menu. But while running an application it has to be done programmatically. Can I provide the library reference to the one currently existing without creating a new one?
    "Create Or Add Library To Project" function in the Datalogging and Supervisory Control (DSC) toolkit does not help in this case. That function, as the name suggests, just tries to create a new library in the project.
    Two possible methods:
    The function "Add Shared Variable To Library" (DSC>EngineControl>Libraries & Processes) needs a library reference, which could be provided via "CreateOrAddLibraryToProject" function, but this function tries to create a new library, and if I provide the path of the existing library it throws an exception that the library already exists in the project (yes, as I wrote above, I need to add new variables to an existing and deployed library).
    OR
    The function "Create Shared Variable" (DSC>EngineControl>Variables & I/O Servers) will add Shared Variable in a process, and not physically in a library file, and the problem (limitation) with this approach is that it doesn't allow to add complex data type Shared Variables (for example in LabVIEW 8.6 it has only 4 datatype options in input parameter, and even in LV2010 it does not have "Image" datatype that I need).
    The scond method is my preferred method as it allows to work on Online Shared Variables and doesn't create them physically in libraries (and this is good as the variables' scope remains only till the Variable Engine is running). But it doesn't support advanced data types, and the first method is powerful in terms that it supports to virtually any datatype, it just seems tricky to get that reference to the library.
    Any tips?
    Thanks ahead!
    Vaibhav

       <<<<>>>>   
    As the above two images show, while a library does not exist, it is easy to use the "CreateOrAddLibraryToProject.vi" which will add a new library to the project (if it doesn't exist on file system, a new library will be created) and that way, using the reference (the green wire going out from the function and the Case Structure, can be used to add Shared Variables to the library. The problem was what to do when a library already exists in the project, how to add more variables to it. I was looking for a way to get a library reference, and somehow I could not see it inside a Project's property (VI Server functions). Hence I posted the question. And upon continuing my search, I found it on the Application's property list.
    I hope it was useful for someone else as well. And thanks for the replies. Please share a better idea if you have.
    Vaibhav

  • How to move pics from "picture library" to created folder

    Just started using 9310 (from 8330) with new SD card. Have a few pics on it and can't figure out how to transfer a photo in "picture library" into a newly created folder. Was so easy on 8330 with simple "move into folder" option... HELP! Thanks!

    Hello equipagekm, 
    Welcome to the forums.
    The option to move to folder will not be present but what you can do is choose the "cut" option and then once in the new folder hit the menu key and choose "paste".
    Hope this helps. Let us know if you need anything else.
    -SR
    Come follow your BlackBerry Technical Team on twitter! @BlackBerryHelp
    Be sure to click Kudos! for those who have helped you.Click Solution? for posts that have solved your issue(s)!

  • Add Folder to Document Library

    I created a document library. I can add new document to the document library. But I want to add folder my sharepoint site. How can I do this? Is it possible?

    Hi,
    To Create folder inside the document library , Just click on Files Tab at document Library Ribbon.then It will prompt for folder name (enter folder name ) and click on Save.
    If you want to create folder through Programmatically, Pls check below link.
    http://www.c-sharpcorner.com/uploadfile/dhananjaycoder/programmatically-creating-folder-in-sharepoint-document-library/
    If you think it is helpful,Vote As Helpful! And if you see a reply being an answer to the question of the thread, click Mark As Answer.
    Mahesh

  • How to add folder to itunes

    How do you add a folder from your computer to your music library vs. a file.

    Hi Kbosborne89,
    Thanks for visiting Apple Support Communities.
    You should have an option for adding folders to iTunes, as well as individual files. See this article for more information:
    iTunes: About the Add to Library, Import, and Convert functions
    http://support.apple.com/kb/ht1347
    If you want to add files to your iTunes library, you can drag files from the Finder to the appropriate icon on the left side of the iTunes window, or choose File > Add to Library (on Windows, choose Add File to Library or Add Folder to Library) and then select the song file or folder you want to add.
    All the best,
    Jeremy

  • How to add folder from KM content to Portal Favorites for selected users

    Hi all,
    I have cretaed  a folder in KM content (In documents) for uploading implementation related ddocuments.
    how to add this folder in "Portal Favorites" of selected users only.
    Please guide.
    Thanks in advance.

    Hi,
    well one way could be the following.
    Go into KM-Content --> Repository "userhome" --> select the user you want --> navigate into his folder Favorites --> create a new internal link in this folder to the folder you want
    In the favorites of the user there is now a link to the desired folder and after clicking a new window will be opened. You can copy this internal link to the favorites folder of the other users you want.
    Regards
    Alex
    Edited by: Alexander Götz on Apr 16, 2009 5:12 PM

  • To search only images in a particular folder of picture library using content search webpart.

    I have Images library where i am storing images in different folders.I need my content search webpart to search and display images in a particular folder in Images Library.For ex: i need to if my Picture Library Name is 'Images' a folder inside that is
    'Travel' which is having some images.I need my content search webpart to pick images from 'Travel' folder only.Any pointers to this will be helpful.

    Hi,
    According to your post, my understanding is that you want to search images in a particular folder via content search web part.
    When we use the search crawl the items in the images library, it crawls the items and folder with the following URL.
    For folder: http://sp13/PublishingImages/Folder1.
    For Items:
    http://sp13/PublishingImages/Forms/DispForm.aspx?ID=itemID
    It not crawls the items as the path
    http://sp13/PublishingImages/Folder1/Item, then we could not use this path to retrieve the items in the folder.
    As a workaround, we can create a custom field in the image library, such as a choice type field named
    Folders(it contains the folder names), when we create a image, we set the folder name in this field.
    Note: we should new a managed property manually to match the Crawled property.
    Then we can use this field to filter the items in a particular folder as below, it works like a charm in  my environment.
    path:"http://sp13/PublishingImages"   Folders=Folder1
    Thanks & Regards,
    Jason
    Jason Guo
    TechNet Community Support

  • How to add folder name to document library view

    Using Project Server 2010.
    We have a set of standard folders on each of our project sites for Requirements, Development, Testing, etc.  Currently, we display this library like you would see in File Explorer - you see a list of folders at the top, double-click on a folder
    to drill down, etc.
    I want to display these same documents as a straight list of all documents - not grouped into folders - but with the folder name displayed next to it (sort of like an attribute).  I can create the list view easily by selecting the "Show all items
    without folders" option in the view settings; however, the containing folder name is not available as a column name.
    Is this possible?

    I do not think there is an out of the box way to do this.
    The immediate solution that comes to mind is using a workflow, that runs everytime  a document is uploaded/item created, which may be too much for your scenario.
    Cheers,
    Prasanna Adavi, Project MVP
    Blog:
      Podcast:
       Twitter:   
    LinkedIn:
      

  • How to add iphoto 4 pictures to iphoto9

    I have pictures on backup discs from iphoto and want to add them to my mac mini which uses iphoto 9. What is the best way to do this. There are iphoto library folders on the backup disc.

    How did you burn the photos to disk? If you used iPhoto's Share ➙ Burn menu option all you need to do is insert the disk in your optical drive and open iPhoto 09. The mini library on the disc will show up in iPhoto's left hand pane where they can be dragged onto the Photos icon and imported into the library.
    Happy New Year

  • How to add folder/project name to a File Naming preset

    Here's a tip to automatically add the name of the Project or its parent Folder to the filename during Import or Batch Change.
    I always used a custom field for adding my client's name to the filename upon Import or Batch Changing versions or masters. But often I would forget to change the custom name, and since it's auto-populated with the previous entry, I'd end up with a bunch of files with the wrong client's name on them. That looks kind of bad. So once I saw with Aperture 3 you can add the Project name or Folder name when relocating referenced files to the new folder structure, I was excited to be able to do the same for the filenames at import. Well, no such luck. They're not an option when you create a custom File Naming preset.
    However, I recently decided to poke around inside some plist files, and found a workaround. I discovered the format string for Folder Name is %F and Project Name is %P. The trick is getting the code into the Format Field where you create the preset.
    Create a new File Naming preset by choosing "edit" from the Version Name menu during Import or Batch Change. Drag everything you want in the name into the Format field, and enter %F or %P where you want the Folder or Project name. The tricky part is that you can't insert it between two existing criteria. It only works at the very end. After you have it in place, you can drag the criteria around to get it in the order you want.
    The alternative method is to insert the code directly into the plist. PLEASE, always make sure you're working with a copy and have a good backup when you're poking around in such things. If you have trouble getting the code to take from within Aperture, you can try this. Same as above, create a new preset, but this time, enter an F or P where you want the Folder or Project name. Give it a unique preset name and save it. Then Quit Aperture. Navigate to ~/Library/Application Support/Aperture/FileNamingPresets.plist, and make a copy of the file, then open with Property List Editor. Dropdown the plist and then dropdown the item you want to edit. You should recognize it by the preset name. Now the easy part. Click in the FormatString field and insert the % character before the F or P you entered in the Format field. Save and you're done.
    I discovered later that while the Folder and Project name works just fine during import, for some reason only the Project name works during Batch Change. The Folder name simply creates a "-" in the filename.
    In case this is seen as a hack and gets deleted, I'm also submitting it to http://www.macosxhints.com/ and I suspect if anyone from MacCreate sees it, they'll steal it too, as they're known to do.

    I do not think there is an out of the box way to do this.
    The immediate solution that comes to mind is using a workflow, that runs everytime  a document is uploaded/item created, which may be too much for your scenario.
    Cheers,
    Prasanna Adavi, Project MVP
    Blog:
      Podcast:
       Twitter:   
    LinkedIn:
      

  • How to add songs from itunes library to ipod touch 4th gen.?

    i have an ipod touch 4th generation and i have added some new song from the internet to my itunes library. now, how do i add it on to my ipod??

    By:
    iOS: Importing personal photos and videos from iOS devices to your computer

  • How to add Restricted Groups in GPO programmatically?

    I have a requirement where i need to manage (crud) GPO on a server. I was able to create gpo and add some security filters but i could not find any way to add Local group in Restricted groups.
    I am using GPMC class library for C#. Any help will be appreciated.
    Thanks!

    > This works but i am still looking for the way to do it programmatically.
    As said - there is none. At least not from MSFT - they only provide APIs
    to set ADM Template values and GPP Registry.
    If you have a budget, check out
    https://sdmsoftware.com/group-policy-management-products/group-policy-automation-engine/
    Martin
    Mal ein
    GUTES Buch über GPOs lesen?
    NO THEY ARE NOT EVIL, if you know what you are doing:
    Good or bad GPOs?
    And if IT bothers me - coke bottle design refreshment :))

Maybe you are looking for