Traverse the file library folders and files under SPWeb

Source: Internet
Author: User

Traverse the file library folders and files under SPWeb

Background:

Recently, we are working on a MOSS Farm management report. We need to create a management report By Farm, By Site, By Web, By Libray, By Document.

The lifecycle of the retrieved file. During development, Farm can be manually maintained (no more than 10 pieces of data), and site/web can

The web table is obtained, and Libray can be written to the C # Console program by using siteid and webid.

The data of the file library.

Finally, a problem occurs: how to program the SP object model to obtain the Document data.

 

Ideas:

1. Using the SPFold model, Feach traverses the SubFolders object to query the document model objects in the SubFolders.

2. Use spfolder. Files to obtain the document model objects in the current file directory.

3. The above ideas must be solved based on the known file library object SPDocumentLibray, and how to Coding to get the SPFolder object of this file library.

 

Solutions to previous problems,

Suppose we already know the siteid and webid information of the website,

The following describes how to traverse and construct the SPFolder object of all the file libraries on the website.

The Code test is as follows:

Namespace TestWeb
{
Public partial class WebForm1: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
If (! IsPostBack)
{
String br = System. Environment. NewLine;
Guid siteid = new Guid ("5E601555-DD68-4518-889B-95D162A2A348 ");
Guid webid = new Guid ("5A7EF298-C322-4C41-9360-FE68AC63B23B ");
SPSite site = null;
SPWeb web = null;
SPListCollection lists = null;
SPFolder folder = null;
SPFolderCollection folders = null;
String s = "";
Try
{
Site = new SPSite (siteid );
Web = site. OpenWeb (webid );
Lists = web. GetListsOfType (SPBaseType. DocumentLibrary );
Foreach (SPList list in lists)
{
Try
{
Folder = list. RootFolder; // web. GetFolder (list. DefaultViewUrl); // failure: AllItems. aspx
S + = folder. Name + ";" + list. Title + "<br/> ";
}
Catch (Exception xx)
{
S + = xx. Message + ";" + list. Title + "<br/> ";
}
}
}
Catch (Exception ex)
{
Throw ex;
}
Finally
{
Site = null;
Web = null;
}

Response. Write (s );
}
}
}
}

 

 

Test Results

 

The rest is to use SPForder to traverse and collect information about the current file.

And the file information in the current subfolders. It is not described in detail.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.