SharePoint List 查看器

using Microsoft.SharePoint;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SharePointListViewer
{
    public partial class frmMain : Form
    {
        public class HourGlass : IDisposable
        {
            public HourGlass()
            {
                Enabled = true;
            }
            public void Dispose()
            {
                Enabled = false;
            }
            public static bool Enabled
            {
                get { return Application.UseWaitCursor; }
                set
                {
                    if (value == Application.UseWaitCursor) return;
                    Application.UseWaitCursor = value;
                    Form f = Form.ActiveForm;
                    if (f != null && f.Handle != null)   // Send WM_SETCURSOR
                        SendMessage(f.Handle, 0x20, f.Handle, (IntPtr)1);
                }
            }
            [System.Runtime.InteropServices.DllImport("user32.dll")]
            private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
        }

        public frmMain()
        {
            InitializeComponent();
        }

        private SPSite _Site = null;
        private SPWeb _Web = null;
        private SPList _List = null;

        public SPSite Site
        {
            get
            {
                return _Site;
            }
            set
            {
                if (_Site != null)
                {
                    _Site.Dispose();
                    _Site = null;
                }
                _Site = value;
                siteChanged();
                Web = null;
                List = null;
            }
        }

        public SPWeb Web
        {
            get
            {
                return _Web;
            }
            set
            {
                if (_Web != null)
                {
                    _Web.Dispose();
                    _Web = null;
                }
                _Web = value;
                webChanged();
                List = null;
            }
        }

        public SPList List
        {
            get
            {
                return _List;
            }
            set
            {
                _List = value;
                listChanged();
            }
        }

        private void siteChanged()
        {
            if (this.Site == null)
                return;
            var webs = this.Site.AllWebs.Select(w => new KeyValuePair<string, SPWeb>(w.Name, w)).ToList();
            webs.Insert(0, new KeyValuePair<string, SPWeb>("-- Please Select --", null));
            cmbWebs.SelectedIndexChanged -= cmbWebs_SelectedIndexChanged;
            cmbWebs.DataSource = webs;
            cmbWebs.DisplayMember = "Key";
            cmbWebs.ValueMember = "Value";
            cmbWebs.SelectedIndexChanged += cmbWebs_SelectedIndexChanged;
        }

        private void webChanged()
        {
            if (this.Web == null)
                return;
            var lists = this.Web.Lists.Cast<SPList>().Select(l => new KeyValuePair<string, SPList>(l.Title, l)).ToList();
            lists.Insert(0, new KeyValuePair<string, SPList>("-- Please Select --", null));
            cmbLists.SelectedIndexChanged -= cmbLists_SelectedIndexChanged;
            cmbLists.DataSource = lists;
            cmbLists.DisplayMember = "Key";
            cmbLists.ValueMember = "Value";
            cmbLists.SelectedIndexChanged += cmbLists_SelectedIndexChanged;
        }

        private void listChanged()
        {
            if (this.List == null)
            {
                dgvListItems.DataSource = null;
                return;
            }

            var result = getListDataSource(this.List);
            dgvListItems.DataSource = result;
            dgvListItems.AutoGenerateColumns = true;
        }

        private void btnOpenWebSite_Click(object sender, EventArgs e)
        {
            cmbLists.Items.Clear();
            cmbWebs.Items.Clear();

            using (new HourGlass())
            {
                try
                {
                    this.Enabled = false;
                    this.Site = new SPSite(txtSiteUrl.Text);
                    this.Enabled = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

            }
        }

        private void cmbWebs_SelectedIndexChanged(object sender, EventArgs e)
        {
            using (new HourGlass())
            {
                if (cmbWebs.SelectedItem != null)
                {
                    var item = (KeyValuePair<string, SPWeb>) cmbWebs.SelectedItem;
                    if (item.Value != null)
                        this.Web = item.Value;
                }
            }
        }

        private void cmbLists_SelectedIndexChanged(object sender, EventArgs e)
        {
            using (new HourGlass())
            {
                if (cmbLists.SelectedItem != null)
                {
                    var item = (KeyValuePair<string, SPList>) cmbLists.SelectedItem;
                    if (item.Value != null)
                        this.List = item.Value;
                    txtSearchKey.Clear();
                }
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (this.Site != null)
            {
                this.Site.Close();
                this.Site = null;
            }
        }

        private DataTable getListDataSource(SPList list)
        {
            var dt = new DataTable();
            foreach (SPField f in list.Fields)
                dt.Columns.Add(f.StaticName, typeof(string));

            foreach (SPListItem listRow in list.Items)
            {
                if (listRow.Versions.Cast<SPListItemVersion>().FirstOrDefault(v => v.Level == SPFileLevel.Published) != null)
                {
                    var r = dt.NewRow();
                    foreach (DataColumn c in dt.Columns)
                    {
                        if (listRow[c.ColumnName] != null)
                            r[c.ColumnName] = listRow[c.ColumnName].ToString();
                    }
                    dt.Rows.Add(r);
                }
            }
            return dt;
        }

        private void filterGridView(DataGridView dgv, string keyword)
        {
            if (dgv.DataSource == null)
                return;

            dgv.CurrentCell = null;

            var dt = dgv.DataSource as DataTable;
            foreach (DataGridViewRow gRow in dgv.Rows)
            {
                if (string.IsNullOrEmpty(keyword))
                {
                    gRow.Visible = true;
                    continue;
                }

                if (gRow.DataBoundItem == null
                    || gRow.DataBoundItem as DataRowView == null)
                {
                    gRow.Visible = true;
                    continue;
                }

                gRow.Visible = false;

                var s = gRow.Cells[0].Value;

                var row = (gRow.DataBoundItem as DataRowView).Row;
                foreach (DataColumn column in dt.Columns)
                {
                    if (row[column.ColumnName] != null
                        && row[column.ColumnName].ToString().ToUpper().Contains(keyword.ToUpper()))
                    {
                        gRow.Visible = true;
                        break;
                    }
                }
            }
        }

        private void txtSearchKey_TextChanged(object sender, EventArgs e)
        {
            timer1.Stop();
            timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            try
            {
                filterGridView(dgvListItems,txtSearchKey.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

        }

        private void dgvListItems_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            if (e.Value != null
                && !string.IsNullOrEmpty(txtSearchKey.Text)
                && e.Value.ToString().ToUpper().Contains(txtSearchKey.Text.ToUpper()))
            {
                using (Brush foreColorBrush = new SolidBrush(e.CellStyle.ForeColor), keywordColorBrush = new SolidBrush(Color.DodgerBlue))
                {
                    var searchKey = txtSearchKey.Text;

                    // 绘制背景
                    e.PaintBackground(e.ClipBounds, false);

                    //绘制自定义背景
                    var bounds = e.CellBounds;
                    bounds.Inflate(new Size(-1, -1));
                    e.Graphics.FillRectangle(new SolidBrush(Color.Yellow), bounds);

                    // 绘制背景(被选中时)
                    if (e.State == (DataGridViewElementStates.Selected | DataGridViewElementStates.Displayed | DataGridViewElementStates.Visible))
                        e.PaintBackground(e.ClipBounds, true);

                    // 绘制原文本
                    e.Graphics.DrawString(e.Value.ToString(), e.CellStyle.Font, foreColorBrush, e.CellBounds, StringFormat.GenericDefault);

                    // 在原文本上绘制红色关键字
                    //e.Graphics.DrawString(e.Value.ToString(), e.CellStyle.Font, keywordColorBrush, e.CellBounds, StringFormat.GenericDefault);

                    // 已完成事件处理,继续本身处理
                    e.Handled = true;
                } 

            }
        }
    }
}
namespace SharePointListViewer
{
    partial class frmMain
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.btnOpenWebSite = new System.Windows.Forms.Button();
            this.txtSiteUrl = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.cmbWebs = new System.Windows.Forms.ComboBox();
            this.label3 = new System.Windows.Forms.Label();
            this.cmbLists = new System.Windows.Forms.ComboBox();
            this.dgvListItems = new System.Windows.Forms.DataGridView();
            this.splitContainer1 = new System.Windows.Forms.SplitContainer();
            this.label4 = new System.Windows.Forms.Label();
            this.txtSearchKey = new System.Windows.Forms.TextBox();
            this.timer1 = new System.Windows.Forms.Timer(this.components);
            ((System.ComponentModel.ISupportInitialize)(this.dgvListItems)).BeginInit();
            this.splitContainer1.Panel1.SuspendLayout();
            this.splitContainer1.Panel2.SuspendLayout();
            this.splitContainer1.SuspendLayout();
            this.SuspendLayout();
            //
            // btnOpenWebSite
            //
            this.btnOpenWebSite.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.btnOpenWebSite.Location = new System.Drawing.Point(732, 12);
            this.btnOpenWebSite.Name = "btnOpenWebSite";
            this.btnOpenWebSite.Size = new System.Drawing.Size(75, 22);
            this.btnOpenWebSite.TabIndex = 0;
            this.btnOpenWebSite.Text = "Open Site";
            this.btnOpenWebSite.UseVisualStyleBackColor = true;
            this.btnOpenWebSite.Click += new System.EventHandler(this.btnOpenWebSite_Click);
            //
            // txtSiteUrl
            //
            this.txtSiteUrl.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
            | System.Windows.Forms.AnchorStyles.Right)));
            this.txtSiteUrl.Location = new System.Drawing.Point(75, 14);
            this.txtSiteUrl.Name = "txtSiteUrl";
            this.txtSiteUrl.Size = new System.Drawing.Size(651, 20);
            this.txtSiteUrl.TabIndex = 1;
            this.txtSiteUrl.Text = "http://bmsserver:9000/sites/BPM/";
            //
            // label1
            //
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(12, 16);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(44, 13);
            this.label1.TabIndex = 2;
            this.label1.Text = "Site Url:";
            //
            // label2
            //
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(15, 50);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(38, 13);
            this.label2.TabIndex = 3;
            this.label2.Text = "Webs:";
            //
            // cmbWebs
            //
            this.cmbWebs.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
            | System.Windows.Forms.AnchorStyles.Right)));
            this.cmbWebs.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cmbWebs.FormattingEnabled = true;
            this.cmbWebs.Location = new System.Drawing.Point(16, 3);
            this.cmbWebs.Name = "cmbWebs";
            this.cmbWebs.Size = new System.Drawing.Size(295, 21);
            this.cmbWebs.TabIndex = 4;
            this.cmbWebs.SelectedIndexChanged += new System.EventHandler(this.cmbWebs_SelectedIndexChanged);
            //
            // label3
            //
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(7, 7);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(31, 13);
            this.label3.TabIndex = 3;
            this.label3.Text = "Lists:";
            //
            // cmbLists
            //
            this.cmbLists.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
            | System.Windows.Forms.AnchorStyles.Right)));
            this.cmbLists.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cmbLists.FormattingEnabled = true;
            this.cmbLists.Location = new System.Drawing.Point(44, 3);
            this.cmbLists.Name = "cmbLists";
            this.cmbLists.Size = new System.Drawing.Size(281, 21);
            this.cmbLists.TabIndex = 4;
            this.cmbLists.SelectedIndexChanged += new System.EventHandler(this.cmbLists_SelectedIndexChanged);
            //
            // dgvListItems
            //
            this.dgvListItems.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
            | System.Windows.Forms.AnchorStyles.Left)
            | System.Windows.Forms.AnchorStyles.Right)));
            this.dgvListItems.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dgvListItems.Location = new System.Drawing.Point(18, 83);
            this.dgvListItems.Name = "dgvListItems";
            this.dgvListItems.Size = new System.Drawing.Size(789, 378);
            this.dgvListItems.TabIndex = 5;
            this.dgvListItems.CellPainting += new System.Windows.Forms.DataGridViewCellPaintingEventHandler(this.dgvListItems_CellPainting);
            //
            // splitContainer1
            //
            this.splitContainer1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
            | System.Windows.Forms.AnchorStyles.Right)));
            this.splitContainer1.Location = new System.Drawing.Point(59, 39);
            this.splitContainer1.Name = "splitContainer1";
            //
            // splitContainer1.Panel1
            //
            this.splitContainer1.Panel1.Controls.Add(this.cmbWebs);
            //
            // splitContainer1.Panel2
            //
            this.splitContainer1.Panel2.Controls.Add(this.cmbLists);
            this.splitContainer1.Panel2.Controls.Add(this.label3);
            this.splitContainer1.Size = new System.Drawing.Size(680, 38);
            this.splitContainer1.SplitterDistance = 338;
            this.splitContainer1.TabIndex = 6;
            //
            // label4
            //
            this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(18, 476);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(73, 13);
            this.label4.TabIndex = 7;
            this.label4.Text = "搜索关键字:";
            //
            // txtSearchKey
            //
            this.txtSearchKey.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
            | System.Windows.Forms.AnchorStyles.Right)));
            this.txtSearchKey.Location = new System.Drawing.Point(97, 473);
            this.txtSearchKey.Name = "txtSearchKey";
            this.txtSearchKey.Size = new System.Drawing.Size(710, 20);
            this.txtSearchKey.TabIndex = 8;
            this.txtSearchKey.TextChanged += new System.EventHandler(this.txtSearchKey_TextChanged);
            //
            // timer1
            //
            this.timer1.Interval = 1000;
            this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
            //
            // frmMain
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(824, 503);
            this.Controls.Add(this.txtSearchKey);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.splitContainer1);
            this.Controls.Add(this.dgvListItems);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.txtSiteUrl);
            this.Controls.Add(this.btnOpenWebSite);
            this.Name = "frmMain";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "SharePoint List Viewer";
            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.dgvListItems)).EndInit();
            this.splitContainer1.Panel1.ResumeLayout(false);
            this.splitContainer1.Panel2.ResumeLayout(false);
            this.splitContainer1.Panel2.PerformLayout();
            this.splitContainer1.ResumeLayout(false);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Button btnOpenWebSite;
        private System.Windows.Forms.TextBox txtSiteUrl;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.ComboBox cmbWebs;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.ComboBox cmbLists;
        private System.Windows.Forms.DataGridView dgvListItems;
        private System.Windows.Forms.SplitContainer splitContainer1;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.TextBox txtSearchKey;
        private System.Windows.Forms.Timer timer1;
    }
}

SharePoint List 查看器,布布扣,bubuko.com

时间: 2024-10-13 15:11:40

SharePoint List 查看器的相关文章

SharePoint ULS Log Viewer 日志查看器

SharePoint ULS Log Viewer 日志查看器 项目描述 这是一个Windows应用程序,更加轻松方便查看SharePoint ULS日志文件.支持筛选和简单的视图. 信息 这是一个WPF应用程序,LINQ支持. 目前版本有以下特点: 1. 转换和打开多个SharePoint ULS日志(如果选择多个或合并). 2. 记录并改变列大小,在任何列排序. 3. 支持Severity.Category和Process或自定义文本过滤.搜索. 4. 将多行单个日志跟踪记录分组更容易查看.

自己动手实现WIFI密码查看器

最近搬了家,还没来得及装上宽带,于是乎手机上用**万能钥匙偷偷连接了几个WIFI,可是电脑也想用的话,就必须借助工具来查看密码了,之前一贯的做法是使用RE管理器进入系统文件夹查看WIFI配置文件(/data/misc/wifi/wpa_supplicant.conf),后来嫌麻烦又下载了好些WIFI密码查看器,但始终不满意,广告太多了哈哈! 刚好最近自学了不少安卓相关的知识,何不自己实现一个呢? 先来看看成果图吧: 界面布局非常简单,整个程序就只有一个Activity,使用LinearLayou

怎么移动dwg文件查看器中的图形位置

一张图纸中包括图形和文字,图形可以让读者更加容易理解,而文字则是起到了一个解释性的作用.在电脑中打开CAD图纸,需要用到dwg文件查看器,制作过CAD的朋友们都知道CAD文件的格式是dwg格式.图纸中的图形有的时候不在适合位置,就需要把他移动到一个合适的位置上,那么,如何移动呢,来看看具体的操作方法. 如果想要将CAD图形对象移动到指定位置,那么只需要使用迅捷CAD编辑器就可以对CAD图形对象进行移动操作,这是一款专业的CAD编辑软件,软件不仅可以用来浏览和查看DWG.DXF等CAD文件格式,还

六: Image Viewer 离线镜像查看器

参考:http://hadoop.apache.org/docs/r2.6.3/hadoop-project-dist/hadoop-hdfs/HdfsImageViewer.html   离线镜像查看器用于查看HDFS镜像.hadoop2.4之前的镜像查看器与之后的不同,要查看2.4之前的,请用2.3的查看器,或者用oiv_legacyCommand 命令. 输出格式: 1)web http(默认方式) 2)XML 使用方式: 1)web方式 首先启动HTTP REST: 列出有哪些目录: 查

Android笔记二十七.Bitmap之简易图片查看器

转载请表明出处:http://blog.csdn.net/u012637501(嵌入式_小J的天空) 为了增强用户之间的交互,Android系统中提供了一些API和部件给我们开发美观有趣的应用.比如Android系统提供了ImageView来显示静态图片.AnimationDrawble来开发逐帧动画以及通过Animation对普通图片使用不减动画等.另外,Android应用中的图片不仅包括*.png.*.jpg.*.gif等格式的位图,也包括使用XML资源文件定义的各种Drawable对象.关

CentOS6.4下使用默认的文档查看器打开PDF文档乱码的解决方案

 最近在CentOS6.4下使用其默认的文档查看器打开PDF文档时出现乱码的方块,有两种方法可以解决.    方法一:修改/etc/fonts/conf.d/49-sansserif.conf文件,如下: [html] view plaincopy <?xml version="1.0"?> <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> <fontconfig> <!-- If the f

Qt项目实战2:简单的图片查看器(1)

在博文http://www.cnblogs.com/hancq/p/5817108.html中介绍了使用空的Qt项目创建带有菜单栏.工具栏的界面. 这里,使用一个简单的图片查看器项目,来熟悉一下Qt的图片显示和基本操作. 该项目分为两部分: (1)实现图片的打开.关闭.居中显示.上一张/下一张切换 (2)实现图片的放大.缩小.左旋.右旋.另存为等操作 需要用的Qt类: QFileDialog QImage QPixmap QFileInfo 使用空的Qt项目创建带有菜单栏和工具栏的界面的操作参考

安卓开发教程-实战网页源代码查看器,安卓程序员必备

本系列教程致力于可以快速的进行学习安卓开发,按照项目式的方法,通常一篇文章会做一个小程序.提高学习的兴趣. 一方面总结自己所得,另一方面可以通过自己的分享帮助更多学习的同仁. 因为知识的连贯性,推荐按照瞬息进行学习.目录链接:http://www.chengxiaoxiao.com/bozhu/1336.html 本教程由今日头条-做全栈攻城狮原创首发,转载请注明出处. 求兼职:请联系wx:aiquanzhan 页尾提供github源代码下载地址. 一.项目描述: 众所周知,组成网站的每个页面都

android 网络_网络图片查看器

xml <?xml version="1.0"?> -<LinearLayout tools:context=".MainActivity" android:paddingTop="@dimen/activity_vertical_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingLeft="