share point CSOM 客户端模式 创建表 增删改查
需要引用:Microsoft.SharePoint.Client
ascx:
<h4>CSOM所有表名</h4>
<table>
<tr>
<td></td>
<td>
<asp:Button ID="btn_AllTabel_Select" runat="server" Text="检索" OnClick="btn_AllTabel_Select_Click" />
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Label ID="lbl_AllTabel_List" runat="server" Text=""></asp:Label></td>
</tr> </table> <h4>CSOM创建表名</h4>
<table>
<tr>
<td>表名:</td>
<td>
<asp:TextBox ID="txt_Tabel" runat="server"></asp:TextBox></td>
<td>
<asp:Label ID="lbl_Notes_cjbm" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="btn_CreateTabel" runat="server" Text="创建" OnClick="btn_CreateTabel_Click" /></td>
</tr> </table> <h4>CSOM添加数据</h4>
<table>
<tr>
<td>Name:</td>
<td>
<asp:TextBox ID="txt_Name" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Desc:</td>
<td>
<asp:TextBox ID="txt_Desc" runat="server"></asp:TextBox></td>
<td>
<asp:Label ID="lbl_Notes_tjsj" runat="server" Text=""></asp:Label></td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="btn_Add" runat="server" Text="添加" OnClick="btn_Add_Click" /></td>
</tr> </table> <h4>CSOM查找数据</h4>
<table>
<tr>
<td>Name:</td>
<td>
<asp:TextBox ID="txt_Name_Select" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="btn_Select" runat="server" Text="查找" OnClick="btn_Select_Click" /></td>
</tr> </table> <h4>CSOM修改数据</h4>
<table>
<tr>
<td>Id:</td>
<td>
<asp:TextBox ID="txt_Update_Id" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Name:</td>
<td>
<asp:TextBox ID="txt_Update_Name" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Desc:</td>
<td>
<asp:TextBox ID="txt_Update_Desc" runat="server"></asp:TextBox></td>
<td>
<asp:Label ID="lbl_Notes_xfsj" runat="server" Text=""></asp:Label></td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="btn_Update" runat="server" Text="修改" OnClick="btn_Update_Click" /></td>
</tr> </table> <h4>CSOM删除数据</h4>
<table>
<tr>
<td>Id:</td>
<td>
<asp:TextBox ID="txt_Delete_Id" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="btn_Delete" runat="server" Text="删除" OnClick="btn_Delete_Click" /></td>
</tr> </table>
cs:
/// <summary>
/// 创建表名
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btn_CreateTabel_Click(object sender, EventArgs e)
{
//share point 环境 IP
string ServerClientContext = "http://server-sp:10001/sites/gzzwz01";
//share point 环境 账户
string UserName = "administrator@sharepoint.com.cn";
//share point 环境 密码
string PassWord = "@ronger0506"; ClientContext context = new ClientContext(ServerClientContext);
context.Credentials = new NetworkCredential(UserName, PassWord);
var web = context.Web; //表名
string tableName = "tableName"; if (txt_Tabel.Text.Trim() != "")
{
tableName = txt_Tabel.Text.Trim();
} //表名
ListCollection listct = context.Web.Lists;
context.Load(listct); //加载客户端对象list.RootFolder.Folders
context.ExecuteQuery();
foreach (List list in listct)
{
if (list.Title.Equals(tableName, StringComparison.OrdinalIgnoreCase))
{
lbl_Notes_cjbm.Text = tableName + "表已存在。"; return;
}
} ListCreationInformation listCreationInfo = new ListCreationInformation();
listCreationInfo.Title = tableName;
listCreationInfo.TemplateType = (int)ListTemplateType.GenericList;
List list_Info = web.Lists.Add(listCreationInfo);
list_Info.Description = "New Description";
Field field1 = list_Info.Fields.AddFieldAsXml(
@"<Field Type='Text'
DisplayName='Name'/>",
true, AddFieldOptions.DefaultValue);
Field field2 = list_Info.Fields.AddFieldAsXml(
@"<Field Type='Note'
DisplayName='Desc'/>",
true, AddFieldOptions.DefaultValue);
list_Info.Update();
context.ExecuteQuery();
} /// <summary>
/// 添加数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btn_Add_Click(object sender, EventArgs e)
{
//share point 环境 IP
string ServerClientContext = "http://server-sp:10001/sites/gzzwz01";
//share point 环境 账户
string UserName = "administrator@sharepoint.com.cn";
//share point 环境 密码
string PassWord = "@ronger0506"; ClientContext context = new ClientContext(ServerClientContext);
context.Credentials = new NetworkCredential(UserName, PassWord);
var web = context.Web; string _Tabel = txt_Tabel.Text.Trim();
string _Name = txt_Name.Text.Trim();
string _Desc = txt_Desc.Text.Trim(); var list = web.Lists.GetByTitle(_Tabel); ListItemCreationInformation listItemCI = new ListItemCreationInformation();
ListItem item = list.AddItem(listItemCI); item["Title"] = _Name;
item["Name"] = _Name;
item["Desc"] = _Desc;
item.Update();
context.ExecuteQuery();
} /// <summary>
/// 查找数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btn_Select_Click(object sender, EventArgs e)
{ //share point 环境 IP
string ServerClientContext = "http://server-sp:10001/sites/gzzwz01";
//share point 环境 账户
string UserName = "administrator@sharepoint.com.cn";
//share point 环境 密码
string PassWord = "@ronger0506"; ClientContext context = new ClientContext(ServerClientContext);
context.Credentials = new NetworkCredential(UserName, PassWord);
var web = context.Web; string _Tabel = txt_Tabel.Text.Trim();
string _Name = txt_Name_Select.Text.Trim(); var list = web.Lists.GetByTitle(_Tabel); CamlQuery query = new CamlQuery();
query.ViewXml = string.Format(
@"<View>
<Query>
<Where>
<Eq>
<FieldRef Name='Name' />
<Value Type='Text'>{0}</Value>
</Eq>
</Where>
<OrderBy>
<FieldRef Name='Name' Ascending='FALSE' />
</OrderBy>
</Query>
</View>", _Name);
ListItemCollection items = list.GetItems(query);
context.Load(items); context.ExecuteQuery(); for (int i = ; i < items.Count; i++)
{
txt_Update_Id.Text = items[i].Id.ToString();
txt_Update_Name.Text = items[i]["Name"].ToString();
txt_Update_Desc.Text = items[i]["Desc"].ToString();
}
} /// <summary>
/// 修改数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btn_Update_Click(object sender, EventArgs e)
{ //share point 环境 IP
string ServerClientContext = "http://server-sp:10001/sites/gzzwz01";
//share point 环境 账户
string UserName = "administrator@sharepoint.com.cn";
//share point 环境 密码
string PassWord = "@ronger0506"; ClientContext context = new ClientContext(ServerClientContext);
context.Credentials = new NetworkCredential(UserName, PassWord);
var web = context.Web; string _Tabel = txt_Tabel.Text.Trim();
int _id =Convert.ToInt32(txt_Update_Id.Text);
List table_List = context.Web.Lists.GetByTitle(_Tabel); ListItem listItem = table_List.GetItemById(_id); listItem["Name"] = txt_Update_Name.Text.Trim();
listItem["Desc"] = txt_Update_Desc.Text.Trim();
listItem.Update(); context.ExecuteQuery(); } /// <summary>
/// 删除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btn_Delete_Click(object sender, EventArgs e)
{
//share point 环境 IP
string ServerClientContext = "http://server-sp:10001/sites/gzzwz01";
//share point 环境 账户
string UserName = "administrator@sharepoint.com.cn";
//share point 环境 密码
string PassWord = "@ronger0506"; ClientContext context = new ClientContext(ServerClientContext);
context.Credentials = new NetworkCredential(UserName, PassWord);
var web = context.Web; string _Tabel = txt_Tabel.Text.Trim();
int _id = Convert.ToInt32(txt_Delete_Id.Text);
List table_List = context.Web.Lists.GetByTitle(_Tabel); ListItem listItem = table_List.GetItemById(_id); // 删除
listItem.DeleteObject();
context.ExecuteQuery();
} /// <summary>
/// 查询 所有列表
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btn_AllTabel_Select_Click(object sender, EventArgs e)
{
//share point 环境 IP
string ServerClientContext = "http://server-sp:10001/sites/gzzwz01";
//share point 环境 账户
string UserName = "administrator@sharepoint.com.cn";
//share point 环境 密码
string PassWord = "@ronger0506"; ClientContext context = new ClientContext(ServerClientContext);
context.Credentials = new NetworkCredential(UserName, PassWord);
var web = context.Web; context.Load(web.Lists, lists => lists.Include(list => list.Title, list => list.Id));
context.ExecuteQuery(); foreach (List list in web.Lists)
{
lbl_AllTabel_List.Text = lbl_AllTabel_List.Text + list.Title + ",";
} }
share point CSOM 客户端模式 创建表 增删改查的更多相关文章
- share point CSOM 客户端模式 创建 list
/// <summary> /// 创建新的列表 list /// </summary> /// <param name="web"></ ...
- Android(java)学习笔记245:ContentProvider使用(银行数据库创建和增删改查的案例)
1. Android的四大组件: (1)Activity 用户交互的UI界面 (2)Service 后台运行的服务 (3)BroadcastReceiver 广播接收者 (4)ContentPro ...
- Android(java)学习笔记189:ContentProvider使用(银行数据库创建和增删改查的案例)
1. Android的四大组件: (1)Activity 用户交互的UI界面 (2)Service 后台运行的服务 (3)BroadcastReceiver 广播接收者 (4)ContentPro ...
- Django框架(八)--单表增删改查,在Python脚本中调用Django环境
一.数据库连接配置 如果连接的是pycharm默认的Sqlite,不用改动,使用默认配置即可 如果连接mysql,需要在配置文件中的setting中进行配置: 将DATABASES={} 更新为 DA ...
- Django框架(九)—— 单表增删改查,在Python脚本中调用Django环境
目录 单表增删改查,在Python脚本中调用Django环境 一.数据库连接配置 二.orm创建表和字段 三.单表增删改查 1.增加数据 2.删除数据 3.修改数据 4.查询数据 四.在Python脚 ...
- GZFramwork数据库层《四》单据主从表增删改查
同GZFramwork数据库层<三>普通主从表增删改查 不同之处在于:实例 修改为: 直接上效果: 本系列项目源码下载地址:https://github.com/GarsonZhang/G ...
- GZFramwork数据库层《三》普通主从表增删改查
运行结果: 使用代码生成器(GZCodeGenerate)生成tb_Cusomer和tb_CusomerDetail的Model 生成器源代码下载地址: https://github.com/Gars ...
- GZFramwork数据库层《二》单据表增删改查(自动生成单据号码)
运行效果: 使用代码生成器(GZCodeGenerate)生成tb_EmpLeave的Model 生成器源代码下载地址: https://github.com/GarsonZhang/GZCodeGe ...
- GZFramwork数据库层《一》普通表增删改查
运行结果: 使用代码生成器(GZCodeGenerate)生成tb_MyUser的Model 生成器源代码下载地址: https://github.com/GarsonZhang/GZCode ...
随机推荐
- Fully qualified name FQCN
Fully qualified name - Wikipedia https://en.wikipedia.org/wiki/Fully_qualified_name In computer prog ...
- 小程序 当button遇上Flex布局
当需要将button按行排列,当超过一行时,可以换行,从左到右排列,想实现如下效果(实现的比较粗糙,能说明问题就行,呵~~~): 使用Flex布局,在设置主轴方向上对齐方式,使用justify-con ...
- 转:java高并发学习记录-死锁,活锁,饥饿
死锁 两个或两个以上的进程在执行过程中,因争夺资源而造成的一种互相等待的现象,若无外力作用,它们都将无法推进下去. 为什么会产生死锁: ① 因为系统资源不足. ② 进程运行推进的顺序不合适. ③ ...
- Kafka简介及使用
一.Kafka概述 离线部分: Hadoop->离线计算(hdfs / mapreduce) yarn zookeeper->分布式协调(动物管理员) hive->数据仓库(离线计算 ...
- 为什么说”人生苦短,我用python“?
本文不扯什么大道理,只是先介绍Python的背景,然后从实用的角度出发举一两个真实栗子. 首先要想了解要一门语言的好坏,或者为什么招程序员喜欢(卧槽,原来程序员喜欢不是女朋友?)我们的先从语言的产 ...
- docker-compose部署zk集群、kafka集群以及kafka-manager,及其遇到的问题和解决
zk集群docker-compose.yml 1.新建网络 docker network create --driver bridge --subnet --gateway 172.23.0.1 zo ...
- 003-SpringBoot导入xml配置
SpringBoot理念就是零配置编程,但是如果绝对需要使用XML的配置,我们建议您仍旧从一个@Configuration类开始,你可以使用@ImportResouce注解加载XML配置文件,我拿一个 ...
- request.getInputStream() 流只能读取一次问题
问题: 一次开发过程中同事在 sptring interceptor 中获取 request body 中值,以对数据的校验和预处理等操作 .导致之后spring 在读取request body 值做 ...
- linux内核源代码、配置与编译
内核源代码下载:www.kernel.org Linux内核源代码采用树形结构进行组织,非常合理地把功能相关的文件都放在同一个子目录下,使得程序更具可读性. linux内核代码最好不要在windows ...
- PHP 基础篇 - PHP 的 BC MATH 系列数学函数
一.常见问题 用 PHP 做计算时经常会遇到精度带来的问题,下面来看两个常见的例子: 1. 运算比较 下面表达式输出的结果不是相等: <?php echo 2.01 - 0.01 == 2 ? ...