PowerShell base operate about document
来源:互联网 发布:网络唱歌比赛 编辑:程序博客网 时间:2024/04/30 14:13
使用PowerShell创建一个文档库
文档库的操作和操作的列表是类似的,在这一章将会介绍如果创建一个文档库,上传一个文件到文档库中
创建一个文档库,我们同样需要使用SPListCollection中的Add()方法,
PS>$spWeb=Get-SPWeb-Identityhttp://SPServer
PS>$listTemplate=[Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary
PS>$spWeb.Lists.Add("My Documents","My Doc Library",$listTemplate)
使用PowerShell更新一个文档库
我们可以通过GetList()方法查询到我们需要的文档库,
PS>$spDocumentLibrary=$spWeb.GetList("My Documents")
下面我们来修改这个文档库的一些属性信息,比如文档库的说明和是否在快速启动中显示。
PS>$spDocumentLibrary.Description=“Description”
PS>$spDocumentLibrary.OnQuickLaunch= "True"
PS>$spDocumentLibrary.Update()
在SharePoint文档库中可能会存在文件夹,使用文件夹可以更有效的管理文档库中的文件。如果我们要在文档库中创建文件夹,可以使用AddItem方法,就像我们在列表中创建一个列表项目一样。但不同的是我们需要重载另外一个AddItem方法,也就是说我们需要在方法中添加 Microsoft.SharePoint.SPFileSystemObjectType,来声明我们添加的是一个文件或者是一个文件夹。
PS>$spFolder=$spDocumentLibrary.AddItem(
>> "",[Microsoft.SharePoint.SPFileSystemObjectType]::Folder,"My New Folder"
>>)
PS>$spFolder.Update()
使用PowerShell上传一个文件到文档库
上传文件到文档库中,我们需要使用Microsoft.SharePoint.SPFlieCollection类中的Add方法,这个类表示一个文件的集合。
在我们获取文件集合之前,还需要通过Microsoft.SharePoint.SPWeb类中的GetFolder()方法返回的Microsoft.SharePoint.SPFolder,我们要这个类型初始化一个对象变量。
PS>$spFolder=$spWeb.GetFolder("My Documents")
此时我们就可以向这个文件集合中添加文件了。
PS>$spFileCollection=$spFolder.Files
在Microsoft.SharePoint.SPFileCollection类中提供了一个Add方法,用来向文件集合中添加一个文件,这是一个非常通用的方法,有21种重载的定义。我们将会应用的其中一种,我们需要一个文件的绝对地址,文件字节数组,还有一个Bool类型的值,表示在有同名文件时,是否要覆盖。
我们需要先使用Get-ChildItem方法类获取到文件。然后可以通过使用System.IO.FileStream类中提供的放法OpenRead(),来获取文件的字节数组。
PS>$file=Get-ChildItemC:/Documents/MyDoc.docx
PS>$spFileCollection.Add("My Documents/MyDoc.docx",$file.OpenRead(),$false)
当然我们也同时可以上传多个文档到SharePoint文档库中。
PS>Get-ChildItemC:/Documents-filter“*.docx”|ForEach-Object{
>>$spFileCollection.Add(“MyDocuments/$($_.Name)”,$_.OpenRead(),$true)
>>}
- PowerShell base operate about document
- PowerShell base operate about list
- operate
- Document about buildroot
- About English URL document
- Base operation about XMl file
- good blog about android base
- java.lang.IllegalArgumentException: Document base
- java.lang.IllegalArgumentException: Document base
- SharePoint 2010 PowerShell base function abut list
- About protected resource member in base form
- An interesting document about c10k and more
- some thing about the kernel32.dll base address in X64
- Some tips about Abstract base classes and pure virtual functions
- The base operation about Metadata Service in sharepoint 2013
- Do not warn about base configuration if unnecessary
- Operate SSDBGrid
- file operate
- 随机过程考试经验
- 条款8中placement new练习
- WNetAddConnection2 映射网络驱动器
- js 动态添加标签(新增一行,其实很简单,就是几个函数的应用)
- JAVA时间格式化处理
- PowerShell base operate about document
- GPL协议
- Linux下的多线程编程
- 通向架构师的道路(第七天)之漫谈使用ThreadLocal改进你的层次的划分
- Notification使用详解之二:可更新进度的通知
- 网页制作HTML基础标签代码大全
- 清华梦的粉碎—写给清华大学的退学申请
- Linux的fuser命令解析
- 用VS2010 打包含卸载