问题描述
大家好,
我有一个要求,需要将文件从一个SharePoint文档库复制到同一网站集中的另一个文档库.我可以使用SharePoint Management Shell执行此任务.由于我要使用远程服务器,因此没有SharePoint dll文件. 我的同事建议我使用Web客户端对象模型脚本.我们完成了将文件从网络驱动器上传到共享点文档库的任务,如何在共享点内执行?
I had a requirement that needs to copy files from one SharePoint document library to another with in same site collection. I can perform this task with SharePoint Management shell. Since i'm are going to use remote server, there are no SharePoint dll files. My colleague suggested me to use web client object model script. We achieved this task to upload files from network drive to sharepoint document library, how to perform within sharepoint ?
这是我们用来将文件从网络驱动器上传到SharePoint文档库的脚本.
Here is the script we used to upload files from network drive to SharePoint document library.
设置变量
$ doclibrary =" http://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
$ FolderPath ="\\ xxxxxxxxxxxxxx"
$ todaysDate =获取日期
#上传文件
$ webclient =新对象System.Net.WebClient
$ webclient.UseDefaultCredentials = $ true
$ files =([[System.IO.DirectoryInfo](Get-Item $ FolderPath)).GetFiles()
# 写入输出$ files
ForEach($ files中的$ file)
{
if($ file.LastWriteTime.Date -eq $ todaysDate.Date)
{
if($ file.Name.Contains(.xlsx"))
{
写输出$ file
$ webclient.UploadFile($ doclibrary +"/" + $ File.Name,"PUT",$ File.FullName)
写入成功:$ file.name:" >> E:\ logfilesuccess.txt
}
}
其他
{
写入错误:$ file.name:" >> E:\ logfilefail.txt -追加
}
Set the variables
$doclibrary = "http://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
$FolderPath = "\\xxxxxxxxxxxxxx"
$todaysDate = Get-Date
# Upload the file
$webclient = New-Object System.Net.WebClient
$webclient.UseDefaultCredentials = $true
$files = ([System.IO.DirectoryInfo] (Get-Item $FolderPath)).GetFiles()
# write-output $files
ForEach($file in $files)
{
if ($file.LastWriteTime.Date -eq $todaysDate.Date)
{
if($file.Name.Contains(".xlsx"))
{
write-output $file
$webclient.UploadFile($doclibrary + "/" + $File.Name, "PUT", $File.FullName)
Write "Success: $file.name:" >> E:\logfilesuccess.txt
}
}
else
{
Write "Error: $file.name:" >>E:\logfilefail.txt -Append
}
}
请提出任何建议....
Any Suggestions please....
任何人都可以输入一些代码,以便在几个小时或更早的日期之后删除文件吗?
And can any one input some code where I can delete the files after few hours or previous date ?
谢谢
迈克
推荐答案
我们可以使用客户端对象模型(CSOM),服务器端对象模型(SSOM)或Rest将文件从库移动到SharePoint网站中的另一个库.
使用MoveTo方法(方法,或用于将文件移动到特定目标URL的SPFile.MoveTo (在SSOM中使用的方法).
Using MoveTo method (File.MoveTo Method used in CSOM, orSPFile.MoveTo Method used in SSOM) to move the file to the specific destination URL.
此处是使用SSOM将所有文件从一个库移到另一个库的示例:
#Get the web and libraries
这篇关于使用Web客户端对象模型将文件自动从一个文档库移动到另一个文档库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!