Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 811593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:04:11+00:00 2026-05-15T01:04:11+00:00

I have a List which has a two level hierarchy of folders. Something like

  • 0

I have a List which has a two level hierarchy of folders. Something like this:

List
    Folder_1
       SubFolder_1
              Item 1_1_1
              Item 1_1_2
       SubFolder_2
              Item 1_2_1
              Item 1_2_2
              Item 1_2_3
    Folder_2
       SubFolder_1
              Item 2_1_1
              Item 2_1_2
              Item 2_1_3
       SubFolder_2
              Item 2_2_1
              Item 2_2_2

I want to add a list item to a folder depending on some criteria. I don’t want to loop through all folders as the number of folders is more. So, I thought of running a CAML query to get the folder.

Below CAML Query gives me all folders in the list:

<Where>
    <Eq>
        <FieldRef Name='FSObjType' />
        <Value Type='int'>0</Value>
    </Eq>
</Where>

How can I add another condition to the above query so that I can get a specific folder when I know the exact folder name?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T01:04:12+00:00Added an answer on May 15, 2026 at 1:04 am

    You could try using FileLeafRef or FileDirRef as the name. I don’t think that will work, though, as you need an SPFolder object to add a list Item to it and CAML queries return SPListItemCollection. Check out http://msdn.microsoft.com/en-us/library/bb862315.aspx for a list of some fieldnames you could try.

    Since you know the name (and I presume the whole path) of the folder, why don’t you use the SPWeb.GetFolder method to get the folder and then add an item using that folder object?

    The following two links might be useful:

    • http://stsadm.blogspot.com/2007/12/add-list-item.html

    • http://darrinbishop.com/blog/archive/2007/04/08/41.aspx

    A snippet from the second link:

    Creating a SPListItem in a SPFolder
    Using the OM

    Creating a folder (SPFolder) using the
    WSS 3.0 object model is simple.
    Creating a list item (SPListItem) in a
    list is simple as well. It took me
    awhile and a number of emails to
    finally create a list item in an
    existing folder. So here is the code
    to save you some time.

    SPSite site = new SPSite("http://[ServerName/sitename]"); 
    SPWeb web = site.OpenWeb(); 
    SPList list = web.Lists["Tasks"]; 
    
    SPFolder f = web.GetFolder("http://[ServerName/sitename]/Lists/Tasks/Test" );
    if(f.Exists)
    {
       SPListItemCollection itemColl = list.Items;
    
       SPListItem item = itemColl.Add(f.ServerRelativeUrl, 
                                      SPFileSystemObjectType.File,
                                      null);
    
       item["Title"] = "Added from OM";
       item.Update();
    }
    

    If you are uploading a file, the first link will be useful. If it is just a plain list item, the second link (and the code I pasted here) might be useful.

    Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of items, which has two values, a name and an
I have a list view item which has a button and displays properties on
I have a list which has repeating items and I want a list of
I have list in python which has following entries name-1 name-2 name-3 name-4 name-1
I have a list: Collection users which has around 100K+ records of users (all
I have a list of items of type ViewLookupItem which has these properties: For
I have a list of items ('sections') which has a getter and a setter.
I have a list which contains dictionaries. Each dictionary has an attribute description which
I have a List<T> where T is my Event type which has a field
I have a table articles that has a column company which has list of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.