简体   繁体   English

Sharepoint 2010上传文件

[英]Sharepoint 2010 Uploading Documents

How would I go about uploading an entire directory and all sub-directories and files to a SharePoint 2010 Server? 如何将整个目录以及所有子目录和文件上传到SharePoint 2010 Server?

I don't think this function is specifically built into SharePoint (just uploading multiple documents in one folder). 我认为此功能不是SharePoint专门内置的(只需在一个文件夹中上传多个文档)。 But the way I understand it, I can write something in VB or C# to accomplish this. 但是据我了解,我可以用VB或C#编写一些东西来完成此任务。 How would I go about doing this? 我将如何去做呢?

Or is there an easier way to do it? 还是有更简单的方法来做到这一点? The directory I want to upload is huge, so going through folders one by one is out of the question. 我要上载的目录很大,因此不可能一个接一个地浏览文件夹。

Change the view to "Explorer View" and you can drag-and-drop files from a Windows client machine. 将视图更改为“资源管理器视图”,您可以从Windows客户端计算机上拖放文件。 To do it programmatically, you can just copy files to the UNC path like \\\\SERVERNAME\\path\\to\\documentlibrary 要以编程方式执行此操作,您可以将文件复制到UNC路径,例如\\\\ SERVERNAME \\ path \\ to \\ documentlibrary

Note that in WSS 3.0/MOSS 2007 there is an issue if you have versioning enabled on the document library, then you have to "check in" each document after you've dragged 'em in in Explorer View. 请注意,在WSS 3.0 / MOSS 2007中,如果您在文档库上启用了版本控制,则会出现问题,那么在资源管理器视图中将它们拖入它们之后,您必须“签入”每个文档。 (One work-around in that case is you can disable versioning before adding the files.) I don't know if this is still an issue in SP 2010. (在这种情况下,一种解决方法是,可以在添加文件之前禁用版本控制。)我不知道这在SP 2010中是否仍然是问题。

In case you need the codes here it is for mass checkin and mass check outs, as well as recursive copy, do not use .Net 4 Framework as you will get this error 如果您在这里需要用于大量签入和大量签出以及递归副本的代码,请不要使用.Net 4 Framework,因为您会收到此错误

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)

So I suggest to use .Net 3.5 所以我建议使用.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);
    }
}

then run 然后跑

RecursiveCopy(@"C:\LocalFolder\", @"\\sharepoint.com\MyTeamSite\MyDocumentLibrary\");
RecursiveMassCheckIn();

i will also suggest using SharePoint object model here is the below code: 我还将建议使用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);
        }
    }

尝试使用PUT WebRequest( 如此处所用)

In SharePoint 2010, this functionality is provided out of the box. 在SharePoint 2010中,此功能是开箱即用的。

From the Microsoft SharePoint Team Blog : 来自Microsoft SharePoint Team Blog

To add an item to this library, you can click on the Add document button in the view. 要将项目添加到该库中,可以单击视图中的“添加文档”按钮。 That button will always be available at the end of the current page, if you want to quickly add documents to this library. 如果您想将文档快速添加到该库中,该按钮将始终在当前页面的末尾可用。 When you click it, you'll notice that instead of navigating the entire page, we just put up a dialog asking you where you want to upload. 当您单击它时,您会注意到,我们没有导航整个页面,而是打开了一个对话框,询问您要将文件上传到何处。 This makes it faster to load and also easier to understand what's going on. 这使得加载速度更快,也更容易理解正在发生的事情。 For this post, I actually want to upload multiple files – so go ahead and click on Upload Multiple Files. 对于这篇文章,我实际上要上传多个文件-因此,继续并单击“上传多个文件”。

... ...

You can drag files onto the blue rectangle to add them to your upload list, or you can click on Browse for files instead to find the files in a windows dialog. 您可以将文件拖到蓝色矩形上,以将其添加到上传列表中,也可以单击“浏览文件”,而不是在Windows对话框中找到文件。 Once you've picked them, click Ok and they will start uploading 选中它们后,单击确定,它们将开始上传

I just tried this in a SharePoint 2010 Document Library. 我只是在SharePoint 2010文档库中尝试过此操作。 I created a hierarchy of folders and added a couple notepad files to it. 我创建了文件夹层次结构,并向其中添加了几个记事本文件。 I then dragged the topmost folder into the Upload Multiple Files dialog and it uploaded that folder along with all of its subfolders and files. 然后,我将最上面的文件夹拖到“上载多个文件”对话框中,它将该文件夹及其所有子文件夹和文件一起上载。

Note that use of Upload Multiple Files requires Silverlight on the client. 请注意,使用上载多个文件需要在客户端上使用Silverlight。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在SharePoint 2010中预览文档 - Previewing documents in SharePoint 2010 在将文档上载到Sharepoint时添加元数据 - Adding metadata while uploading documents to Sharepoint 获取有关Sharepoint 2010中文档的用户详细活动 - Get user detailed activity on Documents in Sharepoint 2010 使用Sharepoint 2010 Services查询文档列表及其内容 - Querying through a list of documents and its contents with Sharepoint 2010 Services OPENXML是在SharePoint 2010中使用Office文档服务器端的唯一方法吗? - Is OPENXML the only way to work with Office documents server side in SharePoint 2010? 将Excel数据上载到SharePoint 2010上的.Net控件时出现UnauthorizedAccessException - UnauthorizedAccessException while uploading excel Data to .Net control on SharePoint 2010 C#:使用 Web 服务将文档上传到 SharePoint 2010 - C# : Uploading a document to SharePoint 2010 using Web Service 如何使用 c# 以编程方式将文档从 Sharepoint 2010 迁移到 sharepoint online - How to migrate documents from Sharepoint 2010 to sharepoint online programatically using c# 使用Sharepoint 2010客户端对象模型搜索站点中以特定扩展名结尾的所有文档 - Search for all documents in a site that end with a specific extention using Sharepoint 2010 Client Object Model 未找到使用CSOM 404通过Windows服务将文件上传到SharePoint 2010的错误 - Uploading Files to SharePoint 2010 via Windows Service using CSOM 404 not found error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM