Programmatically reading contents of Files inside folders in Document Library and display in to gridview in MOSS 2007

Respondida Programmatically reading contents of Files inside folders in Document Library and display in to gridview in MOSS 2007

  • Dienstag, 1. Mai 2012 15:47
     
     

    Hi,

    I have multiple folders in SharePoint document  library(MOSS 2007), each of the folders contains multiple files. My requirement is to get all files :Title, Name , Modified Date, Modified By and to display in to grid view.I was using CAML query but not able to get the files name inside the folder only folders name are returning as a query result. Please help.

Alle Antworten

  • Dienstag, 1. Mai 2012 16:21
     
      Enthält Code

    //Try this

    <ViewScope='Recursive'> <Query> <Where> ... </Where> <QueryOptions> <ViewAttributes Scope='Recursive' /> </QueryOptions> <RowLimit>100</RowLimit> </Query> </View>


    -Sangeetha

  • Montag, 7. Mai 2012 09:30
     
     Beantwortet Enthält Code

    Hi Ravi,

    In you CAML query, you should set

    Query.ViewAttributes = "Scope=\"RecursiveAll\"";

    For example:

    using (SPWeb oWebsite = SPContext.Current.Site.AllWebs["Site_Name"])
    {
        SPList oList = oWebsite.Lists["DocLib_Name"];
        SPView oView = oList.Views["View_Name"];
    
        SPQuery oQuery = new SPQuery(oView);
        oQuery.ViewAttributes = "Scope=\"Recursive\"";
        SPListItemCollection collListItemsAvailable = 
          oList.GetItems(oQuery);
    
        foreach (SPListItem oListItemAvailable in collListItemsAvailable)
        {
            Response.Write(SPEncode.HtmlEncode(oListItemAvailable["Name"]) + 
              "<BR>");
        }
    }

    For more information, please refer to:

    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.viewattributes.aspx

    Thanks,
    Simon


    Simon Huang

    TechNet Community Support

  • Montag, 7. Mai 2012 09:49
     
     Beantwortet

    Hi,

    I have come across the same requirement.I blogged it.

    Looping all folders and retrieve the file name

    You need to put one more foreach loop inside the SPFolder to loop all the files inside.


    Murugesa Pandian.,MCTS|App.Devleopment|Configure