会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
山前客栈
这家伙很懒,什么也没留下......
首页
新随笔
订阅
管理
C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
using
Microsoft.SharePoint;
SPWeb site
=
SPControl.GetContextWeb(Context);
SPListItemCollection items
=
site.Lists[
"
ListName
"
].Items;
SPListItem item
=
items.Add();
item[
"
Field_1
"
]
=
OneValue;
item[
"
Field_2
"
]
=
TwoValue;
item.Update();
删除sharepoint list数据
=============================================
using
Microsoft.SharePoint;
SPWeb site
=
SPControl.GetContextWeb(Context);
SPListItemCollection items
=
site.Lists[
"
ListName
"
].Items;
items[
0
].Delete();
上传文件到sharepoint
=============================================
using
System.IO;
using
Microsoft.SharePoint;
if
( htmlInputFile1.PostedFile
!=
null
)
{
SPWeb site
=
new
SPSite(destinationURL).OpenWeb();
Stream stream
=
htmlInputFile1.PostedFile.InputStream;
byte
[] buffer
=
new
bytes[stream.Length];
stream.Read(buffer,
0
, (
int
) stream.Length);
stream.Close();
site.Files.Add(destinationURL, buffer);
}
查询记录及更新数据
===============================================
using
Microsoft.SharePoint;
SPWeb web
=
new
SPSite(
"
http://nick
"
).OpenWeb(
"
test
"
);
//
Open website
web.AllowUnsafeUpdates
=
true
;
SPList list
=
web.Lists[
"
ListName
"
];
SPQuery query
=
new
SPQuery();
query.Query
=
"
<Where>
"
+
"
<And><And>
"
+
"
<Eq><FieldRef Name=\
"
Filed_1\
"
/><Value Type=\
"
Text\
"
>Test</Value></Eq>
"
+
"
<Eq><FieldRef Name=\
"
Filed_2\
"
/><Value Type=\
"
Text\
"
>
"
+
(
string
)OneValue
+
"
</Value></Eq>
"
+
"
</And>
"
+
"
<Eq><FieldRef Name=\
"
Filed_3\
"
/><Value Type=\
"
Text\
"
>
"
+
(
string
)TwoValue
+
"
</Value></Eq>
"
+
"
</And>
"
+
"
</Where>
"
;
query.RowLimit
=
10
;
//
查询
SPListItemCollection items
=
list.GetItems(query);
try
{
if
(Items.Count
!=
0
)
{
//
更新sharepoint list 数据
foreach
(SPListItem list
in
listItems)
{
list[
"
Filed_1
"
]
=
TextBox1.text.ToString();
list[
"
Filed_2
"
]
=
TextBox2.text.ToString();
list[
"
Filed_3
"
]
=
TextBox3.text.ToString();
listItem.Update();
}
}
else
{
//
将数据记录添加进sharepoint
SPListItem addlist
=
List.Items.Add();
addlist[
"
Filed_1
"
]
=
TextBox1.Text.ToString();
addlist[
"
Filed_2
"
]
=
TextBox2.Text.ToString();
addlist[
"
Filed_3
"
]
=
TextBox3.Text.ToString();
addlist.Update();
}
}
catch
{
}
转自:http://www.cnblogs.com/jhobo/archive/2007/06/06/773650.html
posted on
2007-11-12 15:21
山 前
阅读(
636
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部