SharePoint List 查看器
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 查看器的更多相关文章
- SharePoint ULS Log Viewer 日志查看器
SharePoint ULS Log Viewer 日志查看器 项目描写叙述 这是一个Windows应用程序,更加轻松方便查看SharePoint ULS日志文件.支持筛选和简单的视图. 信息 这是一 ...
- Map工具系列-08-map控件查看器
所有cs端工具集成了一个工具面板 -打开(IE) Map工具系列-01-Map代码生成工具说明 Map工具系列-02-数据迁移工具使用说明 Map工具系列-03-代码生成BySQl工具使用说明 Map ...
- wpf 仿QQ图片查看器
参考博客 WPF下的仿QQ图片查看器 wpf图片查看器,支持鼠标滚动缩放拖拽 实现效果 主要参考的WPF下的仿QQ图片查看器,原博主只给出了部分代码. 没有完成的部分 1.右下角缩略图是原图不是缩略图 ...
- Win10系统怎样让打开图片方式为照片查看器
转载自:百度经验 http://jingyan.baidu.com/article/5d368d1ef0cad13f60c057e3.html 1.首先,我们需要使用注册表编辑器来开启Win10系统照 ...
- 发布两款JQ小插件(图片查看器 + 分类选择器),开源
图片查看器,github地址:https://github.com/VaJoy/imgViewer 效果如下: 这款当初大概写了2小时,有点匆忙地赶出来的,使用的接口很简单: $.bindViewer ...
- IIS事件查看器_WebServer事件查看器_帮助查看IIS-Web服务器事件执行日志
IIS服务器是我们常用的Web站点部署工具,而我们有时可能遇到IIS服务器的应用程序池莫名其妙的关闭了,或者是其他未知原因等等,我们这是可以通过微软提供的WebServer(Web服务事件查看器),来 ...
- wpf图片查看器,支持鼠标滚动缩放拖拽
最近项目需要,要用到一个图片查看器,类似于windows自带的图片查看器那样,鼠标滚动可以缩放,可以拖拽图片,于是就写了这个简单的图片查看器. 前台代码: <Window x:Class=&qu ...
- 在Windows 10下启用旧的照片查看器
从Windows 10开始,默认只能通过“照片”来查看图片了,非常不方便!通过将下列文本保存在.reg文件后导入,即可找回Windows XP时代的“照片查看器”. Windows Registry ...
- 解决Win10图片打开方式没有“Windows照片查看器”问题
1.打开注册表编辑器(Win+R,Regedit),定位至(建议修改前备份注册表): HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Photo Viewe ...
随机推荐
- 控制台应用程序中Main函数的args参数
在VS中添加参数 菜单 项目 -- 你的项目属性 -- 调试 -- 启动选项 -- 命令行参数 参数之间用空格分隔开就可以了,如果参数有空格,以双引号风格
- (spring-第4回【IoC基础篇】)spring基于注解的配置
基于XML的bean属性配置:bean的定义信息与bean的实现类是分离的. 基于注解的配置:bean的定义信息是通过在bean实现类上标注注解实现. 也就是说,加了注解,相当于在XML中配置了,一样 ...
- Jdk配置串在profile中
JAVA_HOME=/home/will/appSource/jdk1.7.0_25PATH=$JAVA_HOME/bin:$PATHCLASSPATH=.:$JAVA_HOME/lib/dt.jar ...
- HDU-4828 卡特兰数+带模除法
题意:给定2行n列的长方形,然后把1—2*n的数字填进方格内,保证每一行,每一列都是递增序列,求有几种放置方法,对1000000007取余: 思路:本来想用组合数找规律,但是找不出来,搜题解是卡特兰数 ...
- 10、网页制作Dreamweaver(扩展:各浏览器对 onunload 事件的支持与触发条件实现有差异)
标准参考 在 HTML 4.01 规范中关于 onunload 事件的描述是:当 document 从 window 中移除时,触发 onunload 事件. 关于 HTML 4.01 规范中 onu ...
- magento -- 给后台分类管理页的分类商品加一栏商品类型
当使用特定分类来控制前台的商品显示时,后台分类管理页的分类商品只有编号.名称.SKU和价格这几栏,选择特定商品相当不便. 可以在这里多加一栏商品类型用来筛选商品,添加的方式很简单. 打开文件/app/ ...
- HDU 1003 Max Sum(AC代码)
#include <stdio.h> int main(){ int i,t,j,n,x; int start,end,temp,max,sum; scanf("%d" ...
- css让一个正方形方块垂直居中
这里有top和margin-top的区别,top(left,right,bottom)是绝对定位,要用position,margin-top是相对定位,相对于相邻的元素或者父元素. 代码如下: < ...
- dedecms内容页调用缩略图 缩略图多种用法(借鉴)
文章内容页调用缩略图方法如下两种.第一种没有大小设置.原图显示.第二种.可以设大小, (1) {dede:field.image/} (2)<img src="{dede:field. ...
- 【转】Java中如何遍历Map对
在Java中如何遍历Map对象 How to Iterate Over a Map in Java 在java中遍历Map有不少的方法.我们看一下最常用的方法及其优缺点. 既然java中的所有map都 ...