代码操作Sharepoint文档库(创建、上传附件)

做项目中遇到客户需求,根据Infopath表单生成Excel并上传到Sharepoint指定文档库中

创建文档库

复制代码
SPSite site = new SPSite(siteurl);
SPListItem item = site.AllWebs["网站名"].Lists["列表名"].Folders.Add("文档库URL", SPFileSystemObjectType.Folder);
item["Name"] = your folder name;
site.RootWeb.AllowUnsafeUpdates = true;
item.Update();
site.RootWeb.AllowUnsafeUpdates = false;
复制代码

上传文件到指定文档库

复制代码
FileStream fs = new FileStream(direct, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
Byte[] filecontents = br.ReadBytes((int)fs.Length);
br.Close();
fs.Close();
SPFolder folder = site.RootWeb.GetFolder("文档库url");
string foldername = 上传上去的文档URL;
site.RootWeb.AllowUnsafeUpdates = true;
SPFile sofle = folder.Files.Add(foldername, filecontents, true);
site.RootWeb.AllowUnsafeUpdates = false;
复制代码

转载于:https://www.cnblogs.com/ningang/p/4321726.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个使用 SharePoint Java SDK 连接 SharePoint 并读取列表数据的示例代码: ```java import com.microsoft.sharepoint.*; import java.net.URL; public class SharePointExample { public static void main(String[] args) { try { // Connect to SharePoint site String siteUrl = "http://sharepoint.example.com/"; String username = "username"; String password = "password"; SharePointOnlineCredentials creds = new SharePointOnlineCredentials(username, password); Authenticator.setDefault(new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password.toCharArray()); } }); URL url = new URL(siteUrl); ClientContext ctx = new ClientContext(url); ctx.setCredentials(creds); // Read list data List list = ctx.getWeb().getLists().getByTitle("ListTitle"); CamlQuery query = new CamlQuery(); ListItemCollection items = list.getItems(query); ctx.load(items); ctx.executeQuery(); // Process list data for (ListItem item : items) { System.out.println(item.getFieldValueAsText("Title")); } } catch (Exception e) { e.printStackTrace(); } } } ``` 这个示例演示了如何使用 SharePoint Java SDK 连接到 SharePoint 网站,并读取名为 "ListTitle" 的列表中的数据。使用 SharePointOnlineCredentials 类提供用户名和密码进行身份验证。然后,使用 ClientContext 类连接到 SharePoint 网站,并使用 getItems() 方法检索列表项。最后,使用 load() 和 executeQuery() 方法加载和执行查询,然后使用 ListItem 类处理每个列表项。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值