SharePoint2007列表辅助小工具
2009-02-11 13:13 Virus-BeautyCode 阅读(926) 评论(0) 编辑 收藏 举报通过这个工具可以查看一个列表的每个栏目的InteralName和DisplayName,还有就是SPField的Type(也就是栏目对应的SharePoint的类型),还有通过item.GetFormattedValue("InteralName")和item["InteralName"]获取的值,这两个方法获取的值是不一样的,前者是经过处理的,后者是没有经过处理的。还可以在下面查看SPList中SPFolder的情况
新建一个WinForm项目,全部代码如下,工具的不足就是只能在安装SharePoint环境的机器上使用
Code
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;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
namespace SharePointHelper
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private string strSPSiteURL = string.Empty;
public string SPSiteURL
{
get
{
return strSPSiteURL;
}
set
{
strSPSiteURL = value;
}
}
private string strSPWebURL = string.Empty;
public string SPWebURL
{
get
{
return strSPWebURL;
}
set
{
strSPWebURL = value;
}
}
private void btnConnect_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txtSPSiteURL.Text))
{
errorProvider1.SetError(txtSPSiteURL, "请输入要显示的网站集的URL");
txtSPSiteURL.SelectAll();
txtSPSiteURL.Focus();
}
else
{
errorProvider1.SetError(txtSPSiteURL, "");
strSPSiteURL = txtSPSiteURL.Text.Trim();
}
//if(string.IsNullOrEmpty(txtSPWebURL.Text))
//{
// errorProvider1.SetError(txtSPWebURL, "请输入要显示的网站的URL");
// txtSPWebURL.SelectAll();
// txtSPSiteURL.Focus();
//}else
//{
// errorProvider1.SetError(txtSPWebURL,"");
// strSPWebURL=txtSPWebURL.Text.Trim();
//}
strSPWebURL = txtSPWebURL.Text.Trim();
try
{
using (SPSite site = new SPSite(SPSiteURL))
{
using (SPWeb web = site.OpenWeb(SPWebURL))
{
SPListCollection lists = web.Lists;
tvSPWebList.Nodes.Clear();
TreeNode rootNode = new TreeNode(SPSiteURL);
TreeNode secondNode = new TreeNode("Lists");
rootNode.Nodes.Add(secondNode);
foreach (SPList list in lists)
{
secondNode.Nodes.Add(list.Title);
}
tvSPWebList.Nodes.Add(rootNode);
tvSPWebList.ExpandAll();
}
}
}
catch (Exception ex)
{
MessageBox.Show("请注意输入格式,或者将错误信息发送到:jorden008@163.com\n错误信息如下:"+ex.Message);
}
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
Form_About about = new Form_About();
about.ShowDialog();
}
private void Form1_Load(object sender, EventArgs e)
{
//txtSPSiteURL.Focus();
}
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
SendKeys.Send("{TAB}");
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void tvSPWebList_AfterSelect(object sender, TreeViewEventArgs e)
{
dataItems.Columns.Clear();
DataTable dtItems = new DataTable();
DataColumn colItems;
DataRow rowItems;
dataFolders.Columns.Clear();
DataTable dtFolders = new DataTable();
DataColumn colFolders;
DataRow rowFolders;
TreeNode clickNode = e.Node;
if (clickNode.Parent.Text.Equals("Lists"))
{
using (SPSite site = new SPSite(SPSiteURL))
{
using (SPWeb web = site.OpenWeb(SPWebURL))
{
SPList list = web.Lists[clickNode.Text];
rowItems = dtItems.NewRow();
rowFolders = dtFolders.NewRow();
foreach (SPField field in list.Fields)
{
colItems = new DataColumn(field.InternalName);
colFolders = new DataColumn(field.InternalName);
dtItems.Columns.Add(colItems);
dtFolders.Columns.Add(colFolders);
rowItems[colItems] = field.Title;
rowFolders[colFolders] = field.Title;
}
dtItems.Rows.Add(rowItems);
dtFolders.Rows.Add(rowFolders);
rowItems = dtItems.NewRow();
rowFolders = dtFolders.NewRow();
foreach (SPField field in list.Fields)
{
rowItems[field.InternalName] = field.Type;
rowFolders[field.InternalName] = field.Type;
}
dtItems.Rows.Add(rowItems);
dtFolders.Rows.Add(rowFolders);
if (list.ItemCount > 0)
{
rowFolders = dtFolders.NewRow();
foreach (SPField field in list.Fields)
{
rowFolders[field.InternalName] = "item.GetFormattedValue";
}
dtFolders.Rows.Add(rowFolders);
rowFolders = dtFolders.NewRow();
foreach (SPField field in list.Fields)
{
rowFolders[field.InternalName] = "item[InteralName]";
}
dtFolders.Rows.Add(rowFolders);
//显示列表下面的folder
foreach (SPListItem item in list.Folders)
{
rowFolders = dtFolders.NewRow();
foreach (SPField field in item.Fields)
{
rowFolders[field.InternalName] = item.GetFormattedValue(field.InternalName);
}
dtFolders.Rows.Add(rowFolders);
rowFolders = dtFolders.NewRow();
foreach (SPField field in item.Fields)
{
rowFolders[field.InternalName] = item[field.InternalName];
}
dtFolders.Rows.Add(rowFolders);
}
dataFolders.DataSource = dtFolders;
rowItems = dtItems.NewRow();
foreach (SPField field in list.Fields)
{
rowItems[field.InternalName] = "item.GetFormattedValue(field.InternalName)";
}
dtItems.Rows.Add(rowItems);
rowItems = dtItems.NewRow();
foreach (SPField field in list.Fields)
{
rowItems[field.InternalName] = "item[field.InternalName]";
}
dtItems.Rows.Add(rowItems);
//显示列表的item
foreach (SPListItem item in list.Items)
{
rowItems = dtItems.NewRow();
foreach (SPField field in item.Fields)
{
rowItems[field.InternalName] = item.GetFormattedValue(field.InternalName);
}
dtItems.Rows.Add(rowItems);
rowItems = dtItems.NewRow();
foreach (SPField field in item.Fields)
{
rowItems[field.InternalName] = item[field.InternalName];
}
dtItems.Rows.Add(rowItems);
}
dataItems.DataSource = dtItems;
}
}
}
}
}
}
}
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;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
namespace SharePointHelper
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private string strSPSiteURL = string.Empty;
public string SPSiteURL
{
get
{
return strSPSiteURL;
}
set
{
strSPSiteURL = value;
}
}
private string strSPWebURL = string.Empty;
public string SPWebURL
{
get
{
return strSPWebURL;
}
set
{
strSPWebURL = value;
}
}
private void btnConnect_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txtSPSiteURL.Text))
{
errorProvider1.SetError(txtSPSiteURL, "请输入要显示的网站集的URL");
txtSPSiteURL.SelectAll();
txtSPSiteURL.Focus();
}
else
{
errorProvider1.SetError(txtSPSiteURL, "");
strSPSiteURL = txtSPSiteURL.Text.Trim();
}
//if(string.IsNullOrEmpty(txtSPWebURL.Text))
//{
// errorProvider1.SetError(txtSPWebURL, "请输入要显示的网站的URL");
// txtSPWebURL.SelectAll();
// txtSPSiteURL.Focus();
//}else
//{
// errorProvider1.SetError(txtSPWebURL,"");
// strSPWebURL=txtSPWebURL.Text.Trim();
//}
strSPWebURL = txtSPWebURL.Text.Trim();
try
{
using (SPSite site = new SPSite(SPSiteURL))
{
using (SPWeb web = site.OpenWeb(SPWebURL))
{
SPListCollection lists = web.Lists;
tvSPWebList.Nodes.Clear();
TreeNode rootNode = new TreeNode(SPSiteURL);
TreeNode secondNode = new TreeNode("Lists");
rootNode.Nodes.Add(secondNode);
foreach (SPList list in lists)
{
secondNode.Nodes.Add(list.Title);
}
tvSPWebList.Nodes.Add(rootNode);
tvSPWebList.ExpandAll();
}
}
}
catch (Exception ex)
{
MessageBox.Show("请注意输入格式,或者将错误信息发送到:jorden008@163.com\n错误信息如下:"+ex.Message);
}
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
Form_About about = new Form_About();
about.ShowDialog();
}
private void Form1_Load(object sender, EventArgs e)
{
//txtSPSiteURL.Focus();
}
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
SendKeys.Send("{TAB}");
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void tvSPWebList_AfterSelect(object sender, TreeViewEventArgs e)
{
dataItems.Columns.Clear();
DataTable dtItems = new DataTable();
DataColumn colItems;
DataRow rowItems;
dataFolders.Columns.Clear();
DataTable dtFolders = new DataTable();
DataColumn colFolders;
DataRow rowFolders;
TreeNode clickNode = e.Node;
if (clickNode.Parent.Text.Equals("Lists"))
{
using (SPSite site = new SPSite(SPSiteURL))
{
using (SPWeb web = site.OpenWeb(SPWebURL))
{
SPList list = web.Lists[clickNode.Text];
rowItems = dtItems.NewRow();
rowFolders = dtFolders.NewRow();
foreach (SPField field in list.Fields)
{
colItems = new DataColumn(field.InternalName);
colFolders = new DataColumn(field.InternalName);
dtItems.Columns.Add(colItems);
dtFolders.Columns.Add(colFolders);
rowItems[colItems] = field.Title;
rowFolders[colFolders] = field.Title;
}
dtItems.Rows.Add(rowItems);
dtFolders.Rows.Add(rowFolders);
rowItems = dtItems.NewRow();
rowFolders = dtFolders.NewRow();
foreach (SPField field in list.Fields)
{
rowItems[field.InternalName] = field.Type;
rowFolders[field.InternalName] = field.Type;
}
dtItems.Rows.Add(rowItems);
dtFolders.Rows.Add(rowFolders);
if (list.ItemCount > 0)
{
rowFolders = dtFolders.NewRow();
foreach (SPField field in list.Fields)
{
rowFolders[field.InternalName] = "item.GetFormattedValue";
}
dtFolders.Rows.Add(rowFolders);
rowFolders = dtFolders.NewRow();
foreach (SPField field in list.Fields)
{
rowFolders[field.InternalName] = "item[InteralName]";
}
dtFolders.Rows.Add(rowFolders);
//显示列表下面的folder
foreach (SPListItem item in list.Folders)
{
rowFolders = dtFolders.NewRow();
foreach (SPField field in item.Fields)
{
rowFolders[field.InternalName] = item.GetFormattedValue(field.InternalName);
}
dtFolders.Rows.Add(rowFolders);
rowFolders = dtFolders.NewRow();
foreach (SPField field in item.Fields)
{
rowFolders[field.InternalName] = item[field.InternalName];
}
dtFolders.Rows.Add(rowFolders);
}
dataFolders.DataSource = dtFolders;
rowItems = dtItems.NewRow();
foreach (SPField field in list.Fields)
{
rowItems[field.InternalName] = "item.GetFormattedValue(field.InternalName)";
}
dtItems.Rows.Add(rowItems);
rowItems = dtItems.NewRow();
foreach (SPField field in list.Fields)
{
rowItems[field.InternalName] = "item[field.InternalName]";
}
dtItems.Rows.Add(rowItems);
//显示列表的item
foreach (SPListItem item in list.Items)
{
rowItems = dtItems.NewRow();
foreach (SPField field in item.Fields)
{
rowItems[field.InternalName] = item.GetFormattedValue(field.InternalName);
}
dtItems.Rows.Add(rowItems);
rowItems = dtItems.NewRow();
foreach (SPField field in item.Fields)
{
rowItems[field.InternalName] = item[field.InternalName];
}
dtItems.Rows.Add(rowItems);
}
dataItems.DataSource = dtItems;
}
}
}
}
}
}
}