我会如何将整个目录以及所有子目录和文件上传到SharePoint 2010 Server?Sharepoint 2010上传文档
我不认为这个功能是专门构建到SharePoint(只需上传一个文件夹中的多个文档)。但是按照我的理解,我可以用VB或C#编写一些东西来实现这一点。我会如何去做这件事?
还是有更简单的方法来做到这一点?我想上传的目录非常庞大,因此逐个浏览文件夹是不可能的。
我会如何将整个目录以及所有子目录和文件上传到SharePoint 2010 Server?Sharepoint 2010上传文档
我不认为这个功能是专门构建到SharePoint(只需上传一个文件夹中的多个文档)。但是按照我的理解,我可以用VB或C#编写一些东西来实现这一点。我会如何去做这件事?
还是有更简单的方法来做到这一点?我想上传的目录非常庞大,因此逐个浏览文件夹是不可能的。
将视图更改为“资源管理器视图”,您可以从Windows客户端计算机上拖放文件。要以编程方式做到这一点,你可以直接将文件复制到像\\服务器\路径\ UNC路径为\ documentlibrary
注意,在WSS 3.0/MOSS 2007有一个问题,如果你已经版本控制的文件启用图书馆,那么你必须在“资源管理器视图”中拖动“em”之后“检入”每个文档。 (在这种情况下,您可以在添加文件之前禁用版本控制。)我不知道这是否仍然是SP 2010中的问题。
尝试使用PUT
WebRequest,like used here。
如果您需要此处的代码,和质量检查超时,以及递归复制,不使用的.Net框架4,你会得到这个错误
Unhandled Exception: System.PlatformNotSupportedException: Microsoft SharePoint
is not supported with version 4.0.30319.1 of the Microsoft .Net Runtime.
at Microsoft.SharePoint.Administration.SPConfigurationDatabase.get_Farm()
at Microsoft.SharePoint.Administration.SPFarm.FindLocal(SPFarm& farm, Boolean
& isJoined)
at Microsoft.SharePoint.SPSite..ctor(String requestUrl)
at SharepointCopy.MassCheckOut()
at SharepointCopy.Process()
at Program.Main(String[] args)
所以我建议使用的.Net 3.5
using System;
using Microsoft.SharePoint;
using System.IO;
public static void RecursiveMassCheckIn()
{
using (SPSite oSharepointSite = new SPSite("http://sharepoint.com/MyTeamSite"))
{
using (SPWeb oSharepointWeb = oSharepointSite.OpenWeb())
{
SPDocumentLibrary oSharepointDocs = (SPDocumentLibrary)oSharepointWeb.Lists["MyDocumentLibrary"];
int iFolderCount = oSharepointDocs.Folders.Count;
//Check in whats on root
MassCheckIn(oSharepointDocs.RootFolder);
//Check in whats on subfolders
for (int i = 0; i < iFolderCount; i++)
{
MassCheckIn(oSharepointDocs.Folders[i].Folder);
}
}
}
}
public static void MassCheckIn(SPFolder oSharepointFolder)
{
foreach (SPFile oSharepointFiles in oSharepointFolder.Files)
{
if (oSharepointFiles.CheckOutType != SPFile.SPCheckOutType.None)
{
oSharepointFiles.CheckIn("Programmatically Checked In");
}
}
}
public static void RecursiveCopy(string sSourceFolder, string sDestinationFolder)
{
if (!Directory.Exists(sDestinationFolder))
{
Directory.CreateDirectory(sDestinationFolder);
}
string[] aFiles = Directory.GetFiles(sSourceFolder);
foreach (string sFile in aFiles)
{
string sFileName = Path.GetFileName(sFile);
string sDestination = Path.Combine(sDestinationFolder, sFileName);
File.Copy(sFile, sDestination);
}
string[] aFolders = Directory.GetDirectories(sSourceFolder);
foreach (string sFolder in aFolders)
{
string sFileNameSub = Path.GetFileName(sFolder);
string sDestinationSub = Path.Combine(sDestinationFolder, sFileNameSub);
RecursiveCopy(sFolder, sDestinationSub);
}
}
然后运行
RecursiveCopy(@"C:\LocalFolder\", @"\\sharepoint.com\MyTeamSite\MyDocumentLibrary\");
RecursiveMassCheckIn();
在SharePoint 2010中,此功能是开箱即用的。
从Microsoft SharePoint Team Blog:
要将项目添加到该库,你 可以点击视图中的添加文件按钮 。如果您想快速将 文档添加到此库,该按钮将始终在当前 页末尾可用 。当你点击它时,你会注意到,而不是 导航整个页面,我们只需 提出一个对话框,询问你在哪里 想要上传。这使得它更快地加载 并且更容易理解 发生了什么事情。对于这篇文章,我 实际上想要上传多个文件 - 所以继续并点击上传 多个文件。
...
您可以将文件拖动到蓝色 矩形将它们添加到您的上传 列表,或者您也可以浏览点击 文件,而不是找一个 Windows对话框中的文件。一旦你选择 它们,单击确定,他们将开始 上传
我只是在SharePoint 2010文档库尝试这样做。我创建了一个文件夹层次结构,并向它添加了一些记事本文件。然后,我将最顶层的文件夹拖入“上载多个文件”对话框,并将其上传到该文件夹及其所有子文件夹和文件。
请注意,使用上传多个文件需要在客户端上使用Silverlight。
我还会建议使用此SharePoint对象模型是下面的代码:
static void Main(string[] args)
{
SPSite site = new SPSite("site url");
SPWeb web = site.OpenWeb();
string stitle = web.Title;
string localPath = "local path";
string documentLibraryName = "Documents";
CreateDirectories(localPath,web.Folders[documentLibraryName].SubFolders);
}
static void CreateDirectories(string path, SPFolderCollection oFolderCollection)
{
//Upload Multiple Files
foreach (FileInfo oFI in new DirectoryInfo(path).GetFiles())
{
FileStream fileStream = File.OpenRead(oFI.FullName);
SPFile spfile = oFolderCollection.Folder.Files.Add
(oFI.Name, fileStream, true);
spfile.Update();
}
//Upload Multiple Folders
foreach (DirectoryInfo oDI in new DirectoryInfo(path).GetDirectories())
{
string sFolderName = oDI.FullName.Split('\\')
[oDI.FullName.Split('\\').Length - 1];
SPFolder spNewFolder = oFolderCollection.Add(sFolderName);
spNewFolder.Update();
//Recursive call to create child folder
CreateDirectories(oDI.FullName, spNewFolder.SubFolders);
}
}
我这个答案达成一致,我使用SP2010的问题仍然是相同的用户仍然需要在要检查的文件。还有一件事要注意“资源管理器视图”只适用于IE。 – Raymund 2010-10-07 00:57:36