zoukankan      html  css  js  c++  java
  • 一个非常有用的webpart文档列表添加文件夹树

    代码很简单:

    //test code by jianyi0115@163.com
    // 2008-11-19
    //
    //
    using System;
    using System.Collections;
    using System.Text;
    using sharepoint = Microsoft.SharePoint.WebControls ;
    using wss = Microsoft.SharePoint.WebPartPages;
    using System.Web.UI.WebControls  ;
    using System.Web.UI;
    using System.Web.UI.Design;
    using System.Runtime.InteropServices;
    using System.Web.UI.WebControls.WebParts;
    using System.Drawing;
    using System.ComponentModel;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.WebControls;

    namespace ThinkingSoft
    {
        [Guid(
    "D55A1423-B38E-4c2e-9303-C234D7B7453E")]
        
    public class TreeListViewWebPart : wss.WebPart                
        {
            
    private string _ListUrl = "http://jyserver:9000/000/Forms/AllItems.aspx" ;
            [WebBrowsable]
            [PersonalizableAttribute]
            [DisplayName(
    "列表Url")]
            
    public string ListUrl
            {
                
    get { return _ListUrl; }
                
    set { _ListUrl = value; }
            }
            
            
    protected override void CreateChildControls()
            {
                
    base.CreateChildControls();
                
    try
                {
                    SPList list 
    = SPContext.Current.Web.GetList(_ListUrl);

                    SPView view 
    = list.DefaultView;

                    SPFolder f 
    = list.RootFolder;

                    TreeView tree 
    = new TreeView();
                    tree.ShowLines 
    = true;

                    
    string viewUrl = Page.Request.RawUrl;

                    
    if (viewUrl.IndexOf("?"!= -1)
                        viewUrl 
    = viewUrl.Split('?')[0];

                    viewUrl 
    += "?RootFolder=";

                    
    string currentUrl = Page.Request.QueryString["RootFolder"];

                    
    this.buildSub(viewUrl, f, tree.Nodes);

                    addHtml(
    "<table width='100%' border='1'><tr><td width='20%' valign='top'>");

                    
    this.Controls.Add(tree);

                    addHtml(
    "</td><td  valign='top'>");
                    
    this.Controls.Add(new LiteralControl(view.RenderAsHtml()));
                    addHtml(
    "</td></table>");
                }
                
    catch (Exception ex)
                {
                    addHtml(ex.Message);                
                }

            }
            
    void addHtml( string html )
            {
                
    this.Controls.Add(new LiteralControl(html));
            } 
            
    //创建文件夹树
            void buildSub( string viewUrl , SPFolder root , TreeNodeCollection nodes )
            {
                
    foreach (SPFolder f in root.SubFolders)
                {
                    
    if (f.Name.ToLower() == "forms"continue;

                    TreeNode n 
    = new TreeNode();
                    n.Text 
    = f.Name;
                    n.NavigateUrl 
    = viewUrl + f.Url;

                    nodes.Add(n);

                    buildSub( viewUrl , f , n.ChildNodes );
                }
            }       
        }
    }



  • 相关阅读:
    PHP form 表单传参明细研究
    php返回数据库查询时出现Resource id #2
    AJAX避免服务器调用上个页面缓存的办法
    错误提示sudo: no tty present and no askpass program specified Sorry, try again.
    lua创建文件和文件夹
    ngx.lua中遇到的小问题2
    [Puzzle] 蚂蚁路线碰撞问题
    [问题记录] 操作符连写
    [工具] XMind
    Qt Creator快捷键
  • 原文地址:https://www.cnblogs.com/jianyi0115/p/964848.html
Copyright © 2011-2022 走看看