简体   繁体   English

将文件从本地复制到SharePoint服务器位置

[英]Copying file from local to SharePoint server location

Now on my PC I can use explorer to open a location on our SP server (location eg http://sp.myhost.com/site/Documents/ ). 现在,在我的PC上,我可以使用资源管理器在SP服务器上打开一个位置(例如, http : //sp.myhost.com/site/Documents/ )。 And from there I can copy/paste a file from eg my C:\\ drive. 从那里,我可以从例如C:\\驱动器复制/粘贴文件。

I need to replicate the copy process progmatically. 我需要以编程方式复制复制过程。 FileCopy() doesn't do it - seems to be the http:// bit that's causing problems! FileCopy()不会执行此操作-似乎是导致问题的http://位!

Does the server allow WebDAV access? 服务器是否允许WebDAV访问? If yes, there are WebDAV clients for Delphi available, including Indy 10 . 如果是,则可以使用Delphi的WebDAV客户端,包括Indy 10

In case if you are not using BLOB storage all SharePoint files are stored in the database as BLOB objects. 如果您不使用BLOB存储,则所有SharePoint文件都将作为BLOB对象存储在数据库中。

When you access your files with explorer you are using windows service which is reading files from SharePoiont and render it to you. 当您使用资源管理器访问文件时,您正在使用Windows服务,该服务正在从SharePoiont读取文件并将其呈现给您。 This way you can copy and paste as soon as donwload them from an to SharePoint manually. 这样,您就可以将它们从手动下载并粘贴到SharePoint中,然后立即进行复制和粘贴。

To be able to do this automatically you should achive this using the next SP API code: 为了能够自动执行此操作,您应该使用下一个SP API代码来实现:

        using (SPSite site = new SPSite("http://testsite.dev"))
        {
            using (SPWeb web = site.OpenWeb())
            {
                using (FileStream fs = File.OpenRead(@"C:\Debug.txt"))
                {
                    byte[] buffer = new byte[fs.Length];
                    fs.Read(buffer, 0, (int) fs.Length);

                    SPList list = web.GetList("Lists/Test AAD");
                    SPFile f = list.RootFolder.Files.Add("/Shared Documents/"+Path.GetFileName(fs.Name), buffer);
                }
            }
        }

This will add new "Debug.txt" file to the "Shared Documents" library read from the disk C. To do this for each file just loop through each file in the folder. 这会将新的“ Debug.txt”文件添加到从磁盘C读取的“共享文档”库中。要对每个文件执行此操作,只需遍历文件夹中的每个文件即可。 You can open web only once and do the loop each time when you add file... 您只能打开一次网络,并且每次添加文件时都要执行循环...

Hope it helps, 希望能帮助到你,

Andrew 安德鲁

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM