Get JSON for all subsites and lists underneath the SPWeb by recursion

Source: Internet
Author: User

1. Reasons for development

In fact, such a lot of tools, in the site a little bit to see is probably able to understand. But it's obsessive-compulsive, and you always want to see it all.

2. Design Ideas

Start is want to make mind map mode, jquery plug-ins, html are searched, the results only found http://qunee.com/buy.html. There is no way, only to find a tree display.

JSON spelling began to receive the capture, the result of writing logic unfamiliar I actually wrote for two or three hours.

Let's publish it and learn it together.

3. Code section

Using system;using system.data;using system.configuration;using system.collections;using System.Web;using System.web.security;using system.web.ui;using system.web.ui.webcontrols;using System.Web.UI.WebControls.WebParts;  Using system.web.ui.htmlcontrols;using Microsoft.sharepoint;public partial class _default:system.web.ui.page{public    String STRR;    bool Isaddlist = true;    String path = "http://xxxx18:8099/1234/";        protected void Page_Load (object sender, EventArgs e) {strr = Getjsonformweb (path);    STRR = "[" + STRR + "]";        public string Getjsonformweb (string path) {string jsonstr = "";                Spsecurity.runwithelevatedprivileges (Delegate {using (SPSite site = new SPSite (path)) { using (SPWeb Web = site. OpenWeb ()) {if (web. webs.count>0) {for (int i = 0; i < Web. Webs.count;               i++) {             Jsonstr + = "{text: '" + "Web" + (i+1). ToString () + "----" + web. Webs[i].                            Name + "'"; if (web. Webs[i].                                Webs.count > 0) {jsonstr + = ", children: ["; Jsonstr + = Getjsonformweb (web. Webs[i].                                URL); if (isaddlist && web. Webs[i]. Lists.count > 0) {jsonstr + = "," + Getlistjson (web.                                Webs[i]);                            } Jsonstr + = "]"; } else {if (isaddlist && web .                                    Lists.count > 0) {jsonstr + = ", children: ["; Jsonstr + = Getlistjson (web.                                    Webs[i]);              Jsonstr + = "]";                  }}//if (web. Webs[i]. Webs.count > 0 && Web. Webs[i].                            Lists.count > 0)//{//Jsonstr + = ",";                            } Jsonstr + = "}"; if (I < web.                            Webs.count-1) {jsonstr + = ",";                                                }}} or else { if (web.                            Lists.count > 0 && isaddlist) {jsonstr + = ", children: [";                            Jsonstr + = Getlistjson (web);                        Jsonstr + = "]"; }} if (web. Webs.count > 0 && Web.                 Lists.count > 0 && isaddlist)   {Jsonstr + = "," + Getlistjson (web);        }                                    }            }        });    return jsonstr; } public string Getlistjson (SPWeb web) {if (!        Isaddlist) {return "";        } string str = ""; if (web. lists.count>0) {for (int i = 0; i < Web. Lists.count; i++) {if (web. Lists[i]. Title.trim (). length>0) {str + = "{text: '" + web. Lists[i].                    Title + "'}"; if (I < web.                    lists.count-1) {str + = ",";    }}}} return str; }}

  

4. Source code:

Development tools: VS2005

http://app.yinxiang.com/shard/s12/sh/765c7019-04ec-4efd-9f83-8e4d0e068c6b/dbab5493b8c06753d4cd6779ec929067

Get JSON for all subsites and lists underneath the SPWeb by recursion

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.