using Microsoft.SharePoint;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
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));
}
}
[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(, 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(, 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)
{
var dt = new DataTable();
dt.Columns.Add("Key", typeof(string));
dt.Columns.Add("Value", typeof(string));
var items = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string,string>("NET Winform gridview 实现多行表头NET Winform Datagridview 实现多行表头", ""),
new KeyValuePair<string,string>("审计署:6家国企违规发放1.7亿元职工福利", ""),
new KeyValuePair<string,string>("电商人为制造的购物伪高潮该停了", ""),
new KeyValuePair<string,string>("Get Started with Microsoft SharePoint Foundation!", "")
};
foreach (var item in items)
{
var r = dt.NewRow();
r["Key"] = item.Key;
r["Value"] = item.Value;
dt.Rows.Add(r);
}
dgvListItems.DataSource = dt;
} 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[].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
{
Debug.Print("Filter start.");
filterGridView(dgvListItems, txtSearchKey.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
} } private void dgvListItems_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
var searchKey = txtSearchKey.Text; if (e.Value != null
&& !string.IsNullOrEmpty(searchKey)
&& e.Value.ToString().ToUpper().Contains(searchKey.ToUpper()))
{
var cellText = e.Value.ToString();
var backGroundColor = Color.Yellow;
var foreColor = e.CellStyle.ForeColor;
var hilightKeyWordColor = Color.Red; // 绘制背景
e.PaintBackground(e.ClipBounds, false); //绘制自定义背景
var bounds = e.CellBounds;
bounds.Inflate(new Size(-, -)); // 绘制背景(被选中时)
if (e.State == (DataGridViewElementStates.Selected | DataGridViewElementStates.Displayed | DataGridViewElementStates.Visible))
{
e.PaintBackground(e.ClipBounds, true);
hilightKeyWordColor = Color.Yellow;
backGroundColor = e.CellStyle.SelectionBackColor;
}
else
{
e.Graphics.FillRectangle(new SolidBrush(backGroundColor), bounds);
hilightKeyWordColor = Color.Red;
} using (Brush foreColorBrush = new SolidBrush(foreColor), keywordColorBrush = new SolidBrush(hilightKeyWordColor))
{
// 绘制原文本
e.Graphics.DrawString(cellText, e.CellStyle.Font, foreColorBrush, e.CellBounds, StringFormat.GenericDefault); //获取关键字之前的文字
var searchKeyIndex = cellText.ToUpper().IndexOf(searchKey.ToUpper());
var textBeforeSearchKey = cellText.Substring(,searchKeyIndex);
var textsearchKey = cellText.Substring(searchKeyIndex, searchKey.Length); //绘制文字
e.Graphics.DrawString(textBeforeSearchKey + textsearchKey, new Font(e.CellStyle.Font, FontStyle.Underline), keywordColorBrush, e.CellBounds, StringFormat.GenericDefault);
e.Graphics.DrawString(textBeforeSearchKey, new Font(e.CellStyle.Font, FontStyle.Underline), new SolidBrush(backGroundColor), e.CellBounds, StringFormat.GenericDefault);
e.Graphics.DrawString(textBeforeSearchKey, new Font(e.CellStyle.Font, FontStyle.Regular), foreColorBrush, 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(, );
this.btnOpenWebSite.Name = "btnOpenWebSite";
this.btnOpenWebSite.Size = new System.Drawing.Size(, );
this.btnOpenWebSite.TabIndex = ;
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(, );
this.txtSiteUrl.Name = "txtSiteUrl";
this.txtSiteUrl.Size = new System.Drawing.Size(, );
this.txtSiteUrl.TabIndex = ;
this.txtSiteUrl.Text = "http://bmsserver:9000/sites/BPM/";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(, );
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(, );
this.label1.TabIndex = ;
this.label1.Text = "Site Url:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(, );
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(, );
this.label2.TabIndex = ;
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(, );
this.cmbWebs.Name = "cmbWebs";
this.cmbWebs.Size = new System.Drawing.Size(, );
this.cmbWebs.TabIndex = ;
this.cmbWebs.SelectedIndexChanged += new System.EventHandler(this.cmbWebs_SelectedIndexChanged);
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(, );
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(, );
this.label3.TabIndex = ;
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(, );
this.cmbLists.Name = "cmbLists";
this.cmbLists.Size = new System.Drawing.Size(, );
this.cmbLists.TabIndex = ;
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(, );
this.dgvListItems.Name = "dgvListItems";
this.dgvListItems.Size = new System.Drawing.Size(, );
this.dgvListItems.TabIndex = ;
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(, );
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(, );
this.splitContainer1.SplitterDistance = ;
this.splitContainer1.TabIndex = ;
//
// 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(, );
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(, );
this.label4.TabIndex = ;
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(, );
this.txtSearchKey.Name = "txtSearchKey";
this.txtSearchKey.Size = new System.Drawing.Size(, );
this.txtSearchKey.TabIndex = ;
this.txtSearchKey.TextChanged += new System.EventHandler(this.txtSearchKey_TextChanged);
//
// timer1
//
this.timer1.Interval = ;
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(, );
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 查看器的更多相关文章

  1. SharePoint ULS Log Viewer 日志查看器

    SharePoint ULS Log Viewer 日志查看器 项目描写叙述 这是一个Windows应用程序,更加轻松方便查看SharePoint ULS日志文件.支持筛选和简单的视图. 信息 这是一 ...

  2. Map工具系列-08-map控件查看器

    所有cs端工具集成了一个工具面板 -打开(IE) Map工具系列-01-Map代码生成工具说明 Map工具系列-02-数据迁移工具使用说明 Map工具系列-03-代码生成BySQl工具使用说明 Map ...

  3. wpf 仿QQ图片查看器

    参考博客 WPF下的仿QQ图片查看器 wpf图片查看器,支持鼠标滚动缩放拖拽 实现效果 主要参考的WPF下的仿QQ图片查看器,原博主只给出了部分代码. 没有完成的部分 1.右下角缩略图是原图不是缩略图 ...

  4. Win10系统怎样让打开图片方式为照片查看器

    转载自:百度经验 http://jingyan.baidu.com/article/5d368d1ef0cad13f60c057e3.html 1.首先,我们需要使用注册表编辑器来开启Win10系统照 ...

  5. 发布两款JQ小插件(图片查看器 + 分类选择器),开源

    图片查看器,github地址:https://github.com/VaJoy/imgViewer 效果如下: 这款当初大概写了2小时,有点匆忙地赶出来的,使用的接口很简单: $.bindViewer ...

  6. IIS事件查看器_WebServer事件查看器_帮助查看IIS-Web服务器事件执行日志

    IIS服务器是我们常用的Web站点部署工具,而我们有时可能遇到IIS服务器的应用程序池莫名其妙的关闭了,或者是其他未知原因等等,我们这是可以通过微软提供的WebServer(Web服务事件查看器),来 ...

  7. wpf图片查看器,支持鼠标滚动缩放拖拽

    最近项目需要,要用到一个图片查看器,类似于windows自带的图片查看器那样,鼠标滚动可以缩放,可以拖拽图片,于是就写了这个简单的图片查看器. 前台代码: <Window x:Class=&qu ...

  8. 在Windows 10下启用旧的照片查看器

    从Windows 10开始,默认只能通过“照片”来查看图片了,非常不方便!通过将下列文本保存在.reg文件后导入,即可找回Windows XP时代的“照片查看器”. Windows Registry ...

  9. 解决Win10图片打开方式没有“Windows照片查看器”问题

    1.打开注册表编辑器(Win+R,Regedit),定位至(建议修改前备份注册表): HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Photo Viewe ...

随机推荐

  1. 收藏的博客--PHP

    32位Win7下安装与配置PHP环境(一至三)  http://blog.csdn.net/yousuosi/article/details/9448903

  2. mysql批量写入

    MySQL批量写入语法是: INSERT INTO table (field1,field2,field3) VALUES (“a”,”b”,”c”), (“a1”,”b1”,”c1”),(“a2”, ...

  3. UIkit框架之UItextfield

    1.继承链:UIcontrol:UIview:UIresponder:NSObject 2.成为第一响应者:[text becomeFirstResponder];  //让该文本成为第一响应者 3. ...

  4. 使用iskindofclass来发现对象是否是某类或其子类的实例

    发现对象是否是特定类或其子类的实例 要发现对象是否是某类或其子类的实例,请在对象上调用 isKindOfClass: 方法.当应用程序需要发现其响应的消息(实现的或继承的),它有时进行以上的检查. s ...

  5. 一个由印度人编写的VC串口类

    http://www.cnblogs.com/lwngreat/p/4098374.html 软件介绍 一个由印度人编写的VC串口类(也是一种VC串口控件),他还配合这个类写了VC 串口通信方面的一些 ...

  6. simple grammer

    <?phpecho strlen("Hello world!"); // outputs 12?> <?phpecho str_word_count(" ...

  7. SQL语句建表、设置主键、外键、check、default、unique约束

    · 什么是数据库? 存放数据的仓库. · 数据库和数据结构有什么区别? 数据结构要解决在内存中操作数据的问题,数据库要解决在硬盘中操作数据的问题.数据结构研究一些抽象数据模型(ADT)和以及定义在该模 ...

  8. Linux基础入门(新版)(实验五至实验八)

    实验五 环境变量与文件查找 (环境变量的作用与用法,及几种搜索文件的方法)   一.环境变量   1.变量 (1)常变量与值是一对一的关系 (2)变量的作用域即变量的有效范围(比如一个函数中.一个源文 ...

  9. 【转】DOM事件简介

    原文转自:http://blog.jobbole.com/52430/ Click.touch.load.drag.change.input.error.risize — 这些都是冗长的DOM(文档对 ...

  10. [转] 3个学习Socket编程的简单例子:TCP Server/Client, Select

    以前都是采用ACE的编写网络应用,最近由于工作需要,需要直接只用socket接口编写CS的代码,重新学习这方面的知识,给出自己所用到的3个简单例子,都是拷贝别人的程序.如果你能完全理解这3个例子,估计 ...