惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

I
InfoQ
D
DataBreaches.Net
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
Martin Fowler
Martin Fowler
Security Latest
Security Latest
Cisco Talos Blog
Cisco Talos Blog
MongoDB | Blog
MongoDB | Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
IT之家
IT之家
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security Affairs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园_首页
L
LINUX DO - 最新话题
Know Your Adversary
Know Your Adversary
S
Schneier on Security
The Last Watchdog
The Last Watchdog
Attack and Defense Labs
Attack and Defense Labs
T
Tenable Blog
G
GRAHAM CLULEY
Y
Y Combinator Blog
P
Palo Alto Networks Blog
L
LINUX DO - 热门话题
Hugging Face - Blog
Hugging Face - Blog
W
WeLiveSecurity
C
Cybersecurity and Infrastructure Security Agency CISA
aimingoo的专栏
aimingoo的专栏
博客园 - 司徒正美
The Register - Security
The Register - Security
T
The Exploit Database - CXSecurity.com
MyScale Blog
MyScale Blog
M
MIT News - Artificial intelligence
Cyberwarzone
Cyberwarzone
雷峰网
雷峰网
T
Tailwind CSS Blog
V2EX - 技术
V2EX - 技术
T
Threat Research - Cisco Blogs
S
Secure Thoughts
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
O
OpenAI News
C
Cyber Attacks, Cyber Crime and Cyber Security
The Cloudflare Blog
量子位
Apple Machine Learning Research
Apple Machine Learning Research
T
Threatpost
S
SegmentFault 最新的问题
小众软件
小众软件
Google DeepMind News
Google DeepMind News
Help Net Security
Help Net Security

博客园 - vuejs3

More on SQL Server Service Broker [转]Android试验:如果View的ID相同会出现什么效果? 父子关系排序,无确定根节点 Silverlight 操作技巧 [文摘]怎么使用Sticky Footer代码(让页脚紧贴页面底部的方法) Sharepoint development toolbox 通过对象模型上传List Template - vuejs3 - 博客园 在文档库中隐藏多文件上传/Disable the Upload Multiple Document option in Document Library - vuejs3 [转]SharePoint Document Library and List – File Upload ASP.NET 2.0 TreeView控件在IE7中断开的连接线 Team Foundation Server讲义 通过CertEnroll在CA上(1创建证书请求2得到证书3安装证书) 如何在WSS中利用KeywordQuery创建搜索查询 SharePoint Web Service的身份验证 【转】免费SharePoint资源 Enum操作技巧 LINQ概述-通用和便利的信息查询方式 NetShopForge网上商店程序(VB)源码—讨论-发布 Microsoft AJAX添加自定义智能感知(intellisense)
SharePoint开发中对ListViewWebPart的几个操作
vuejs3 · 2008-10-28 · via 博客园 - vuejs3

在做一个webPart的时候需要以编程的方式显示一个DocumentLibary。其中用到了ListViewWebPart。用到了一些代码,分享一下。

        Private docLib As SPDocumentLibrary = Nothing
        
Private view As SPView = Nothing
        
Private Web As SPWeb = Nothing

1.初始化(其中的_docLibID和_viewID是属性的私有字段,这个通过GetToolParts方法设置的WebPartToolPart已经被赋值)

        Private Sub InitConfiguration()

            Web 

= SPContext.Current.Site.OpenWeb(SPContext.Current.Web.ServerRelativeUrl)Dim list As SPList = Nothing
            
Try
                list 
= Web.Lists(_docLibID)
                
If list.BaseType = SPBaseType.DocumentLibrary Then
                    docLib 
= TryCast(list, SPDocumentLibrary)
                
End If
            
           
'Set view
            If Me._viewID = Guid.Empty Then
                view 
= docLib.DefaultView
            
Else
                view 
= docLib.Views(Me._viewID)
            
End If
        
End Sub


2.如何创建一个ListViewWebPart 的ToolBar(是根据ListViewWebPart的数据源有关)

只需创建一个SPContex,然后传入view,docLib及其他的信息即可,然后把这个SPContext赋给toolBar的RenderContex即可。

       Private Sub AddViewToolBar()
            
Dim toolbar As New ViewToolBar
            
Dim context As SPContext = SPContext.GetContext(Me.Context, view.ID, docLib.ID, SPContext.Current.Web)

            toolbar.RenderContext 

= context
            Controls.Add(toolbar)
        
End Sub

3.如何创建ListViewWebPart
我把创建的ListViewWebPart放在了一个Panel上面,代码中有个disableToobar这个是移除ListViewWebPart中的ToolBar(看第4,当我们指定ViewGuid ,默认的模式是说含有ToolBar的,这将导致工具栏显示在webpart页)
重要的是给ListName和ViewGui赋值

      Private Function renderExplorerView() As Panel
            
Dim panel As New Panel
            
Dim wp As New ListViewWebPart
            wp.ListName 
= docLib.ID.ToString("B").ToUpper()
            wp.ViewGuid 
= view.ID.ToString("B").ToUpper
            DisableToolbar(wp)
            wp.GetDesignTimeHtml()
            panel.Controls.Add(wp)
            
Return panel
        
End Function

4.如何移除ListViewWebPart中的ToolBar
主要是对SPView中的SPView.ToolbarType设置。在MSDN上是这样描述SPView.ToolbarType
Standard —The most common type of toolbar, which is used, for example, in the All Items views for most lists, and which corresponds to Full Toolbar in the Web Part tool pane.
FreeForm —Used in Default.aspx and Web Part Pages and corresponds to Summary Toolbar in the Web Part tool pane.
None —No toolbar is used in the view, corresponding to No Toolbar in the Web Part tool pane.
我们的目的就是设置ToolbarType是None
VB

 Private Sub DisableToolbar(ByVal lv As ListViewWebPart)
            
' Extract view 
            Dim ViewProp As System.Reflection.PropertyInfo = lv.[GetType]().GetProperty("View", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)Dim spView As SPView = TryCast(ViewProp.GetValue(lv, Nothing), SPView)
            
Dim txt As String = spView.SchemaXml
            
Dim NodeProp As System.Reflection.PropertyInfo = spView.[GetType]().GetProperty("Node", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)
            
Dim node As XmlNode = TryCast(NodeProp.GetValue(spView, Nothing), XmlNode)
            
Dim tBarNode As XmlNode = node.SelectSingleNode("Toolbar")If tBarNode IsNot Nothing Then
                
Dim typeNode As XmlAttribute = tBarNode.Attributes("Type")
                
' make the contents empty so we realy remove the toolbar .. 
                ' otherwise you might get a different type of toolbar popup when we have a 
                ' Migrated site from 2.0 
                tBarNode.RemoveAll()
                
' re-add the type attribute 
                tBarNode.Attributes.Append(typeNode)
                
' finally set the toolbar to not show
                typeNode.Value = "None"
            
End If
            
'This forces a refresh of the views internal xml or the node's cild nodes are not populated 
            Web.AllowUnsafeUpdates = True
            spView.Update()
            Web.AllowUnsafeUpdates 
= False
        
End Sub

C#

private static void DisableToolbar(ListViewWebPart lv)
{
 
//  Extract view 
   System.Reflection.PropertyInfo ViewProp = lv.GetType().GetProperty("View"
    System.Reflection.BindingFlags.NonPublic 
| System.Reflection.BindingFlags.Instance);

   SPView spView 

= ViewProp.GetValue(lv, nullas SPView;string txt = spView.SchemaXml;

   System.Reflection.PropertyInfo NodeProp 

= spView.GetType().GetProperty("Node"
     System.Reflection.BindingFlags.NonPublic 
| System.Reflection.BindingFlags.Instance);

   XmlNode node 

= NodeProp.GetValue(spView, nullas XmlNode;
   XmlNode tBarNode 
= node.SelectSingleNode("Toolbar");if (tBarNode != null)
   {
      XmlAttribute typeNode 
= tBarNode.Attributes["Type"];
      
// make the contents empty so we realy remove the toolbar ..
      
// otherwise you might get a different type of toolbar popup when we have a 
      
// Migrated site from 2.0
      tBarNode.RemoveAll();
      
// re-add the type attribute
      tBarNode.Attributes.Append(typeNode);
      
// finally set the toolbar to not show.
       typeNode.Value = "None";
    }
//This forces a refresh of the views internal xml or the node's cild nodes are not populated 
 spView.Update();
}

5.参考资料
Create custom ListViewWebPart
http://www.sharepointkings.com/2008/08/create-custom-listviewwebpart.html
d
Update ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"
http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826/