• sharepoint webpart 获取文档库下的所有文件夹名


    最近的项目需求中有一个这样的小功能,需要获取到文档库下的所有文件夹名称,并保存到dropdownlist中,代码如下。

    View Code
    protected void Page_Load(object sender, EventArgs e)
            {
                DataBindLoad();
            }
    
            private void DataBindLoad()
            {
                SPSecurity.RunWithElevatedPrivileges(delegate() { // 提升权限
                    try
                    {
                        string ServerUrl = (this.Parent as VisualWebPartUpload).SURL;       //设置的站点地址 http:// xunyi-sps/
                        string LibraryName = (this.Parent as VisualWebPartUpload).Library;  //文档库名称 测试文档库
    
                        using (SPSite site = new Microsoft.SharePoint.SPSite(ServerUrl))//获取站点
                        {
                            SPWeb spWeb = site.OpenWeb();//打开站点
                            spWeb.AllowUnsafeUpdates = true;// 提升权限
                            SPList docLib = spWeb.Lists[LibraryName]; //获取文档库对象
    
                            ///添加文件夹
                            if (this.DroplistType.Items.Count == 0) //将要添加文件夹名的下拉列表
                            {
                                foreach (SPListItem foldername in docLib.Folders) //循环文档库对象listitem Folders指示为文件夹
                                {
                                    this.DroplistType.Items.Add(new ListItem(foldername.Name.ToString(), foldername.UniqueId.ToString())); //添加到下拉列表
                                }
                            }
                        } 
                    }
                    catch (Exception ex)
                    {
                    }
                });
                
            }
  • 相关阅读:
    软链接和硬链接
    Hive的基本常识
    Hadoop
    Docker技术
    人生苦短,我用Python(6)
    人生苦短,我用Python(5)
    人生苦短,我用Python(4)
    openssl telnet openssh
    iptables
    http与httpd
  • 原文地址:https://www.cnblogs.com/zchblog/p/3068780.html
Copyright © 2020-2023  润新知