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 ...
随机推荐
- Uncaught TypeError: Cannot set property 'value' of null
w拼写多一个空格导致. document.getElementById(winput_id).value = value; http://stackoverflow.com/questions/161 ...
- 【转】VMwareCLI命令参考
VMwareCLI命令参考 目录 基本命令范例 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 2 ...
- RESTful API 设计最佳实践【转】
背景 目前互联网上充斥着大量的关于RESTful API(为了方便,后面API和RESTful API 一个意思)如何设计的文章,然而却没有一个“万能”的设计标准:如何鉴权?API格式如何?你的API ...
- SqueezeNet
虽然网络性能得到了提高,但随之而来的就是效率问题(AlexNet VGG GoogLeNet Resnet DenseNet) 效率问题主要是模型的存储问题和模型进行预测的速度问题. Model Co ...
- Java-工程中常用的程序片段
1.字符串-整型相互转换 String s = String.valueOf(2); int a = Integer.parseInt(s); 2.向文件末尾添加内容 BufferedWriter b ...
- mysql复习-来源考试
mysql复习- No1 .登录和权限 (一)常用命令1.登录mysqlmysql -h localhost -u root -p 2.重启mysqlservice mysql restart 延 ...
- 使用selenium
1.安装谷歌浏览器 2.安装谷歌浏览器驱动 3.安装selenium包 4.测试 1.安装谷歌浏览器 2.安装谷歌浏览器驱动 打开 http://blog.csdn.net/huilan_ ...
- Font Awesome-用CSS实现各种小图标icon
Font Awesome为您提供可缩放的矢量图标,您可以使用CSS所提供的所有特性对它们进行更改,包括:大小.颜色.阴影或者其它任何支持的效果.官网:http://fontawesome.dashga ...
- Spring框架第六篇之Spring与DAO
一.Spring与JDBC模板 1.搭建环境 首先导入需要的jar包: 以上jar中多导入了DBCP和C3P0的jar包,因为这里需要演示怎么配置多种数据源,所以导入了这两个包,在实际开发中无需导入这 ...
- 随堂小测app(nabcd)
N 现在,老师想要组织测验,需要提前印制试卷,费时费力,考勤采取传统的点名的方式,过程繁琐且结果水分大. 而随堂小测app通过在线答题,智能定位可以帮助老师掌握学生对知识的掌握程度,了解学生的到客情况 ...