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. powershell命令大全

    Name Category Synopsis ---- -------- -------- ac Alias Add-Content asnp Alias Add-PSSnapin clc Alias ...

  2. (转)Sencha Touch和jQuery Mobile的比较

    原文:http://extjs.org.cn/node/664 Sencha Touch和jQuery Mobile的比较 Posted 周三, 08/07/2013 - 10:07 by admin ...

  3. windows-ubuntu环境变量的设置格式的不同

    1  在Ubuntu下输出环境变量,比如JAVA_HOME, 使用cat或者echo $JAVA_HOME即可,但是在windows下不可以, windows不支持cat命令,只能使用echo %JA ...

  4. BZOJ 1568 Blue Mary开公司

    李超线段树. GTMD调了一下午... #include<iostream> #include<cstdio> #include<cstring> #include ...

  5. php5.2 连接 SQL Server2008

    如果你见到下面这一段输出的话,那么你有福了!!!! Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => ...

  6. 20145210 《Java程序设计》第08周学习总结

    第十四章 NIO与NIO2 14.1 认识NIO •NIO概述 •NIO使用频道来衔接数据结点 •在处理数据时,NIO可以让你设定缓冲区容量 •Channel架构与操作 •isOpen():确认Cha ...

  7. Android弹出选项框及指示箭头动画选择

     Android弹出选项框及指示箭头动画选择 Android原生的Spinner提供了下拉列表选项框,但在一些流行的APP中,原生的Spinner似乎不太受待见,而通常会有下图所示的下拉列表选项框 ...

  8. 通知(Notification) 、 应用间通信(一)

    1 使用通知中心发送消息 1.1 问题 当一个对象需要向多个接受者发送消息的,或者不用知道消息的接收者是谁,就可以使用IOS提供的NSNotificationCenter通知中心,本案例使NSNoti ...

  9. LeetCode Maximum Subarray (最大子段和)

    题意: 给一个序列,求至少含一个元素的最大子段和? 思路: 跟求普通的最大子段和差不多,只不过需要注意一下顺序.由于至少需要一个元素,所以先将ans=nums[0].接下来可以用sum求和了,如果小于 ...

  10. window8快捷键

    win8中有很多比较重要的快捷键经常忘记: cmd快捷键:win+x; 截图工具:win+q; 添加环境变量:右键点击左下角window图标; 添加定时任务:右键点击计算机管理->任务计划程序.