如何以编程方式上载sharepoint 2010文档库中的文件和文件夹。 [英] How to upload the files and folder in sharepoint 2010 document library programatically.

查看:87
本文介绍了如何以编程方式上载sharepoint 2010文档库中的文件和文件夹。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,





我有一个像编程的要求我必须从文件系统上传文件和文件夹到sharepoint 2010文档库。





条件是:用户将在配置文件中传递以下参数:

1)源文件夹位置(来自文件系统)

2)目标sharepoint站点URL。

3)Sharepoint文档库名称。





现在使用对象模型或Web服务我们如何上传文件夹包含从源到目标(文档库)的文件夹层次结构与文件系统中的源层次结构相同。谢谢提前,任何帮助表示赞赏。

Hi all,


I have a requirement like programatically i have to upload files and folder from files system to sharepoint 2010 document library.


Condition is:user will pass the following parameters in the config file:
1)Source folder location(from file system)
2)Destination sharepoint site URL.
3)Sharepoint Document Library Name.


Now using object model or web service how can we upload the folder contains from source to destination(doc library) which will have same folder hierarchy as like source hierarchy in file system.Thanks in advance, any help is appreciated.

推荐答案

创建网站和Web对象并在下面编写此代码:





Create Site and Web Objects and write this code below:


SPFolder myLibrary = Web.Folders[documentLibraryName];

// Prepare to upload
Boolean replaceFiles = true;
String fileName = System.IO.Path.GetFileName(fileToUpload location);
FileStream fileStream = File.OpenRead(fileToUpload location);
// Upload document
SPFile spfile = myLibrary.Files.Add(fileName, fileStream, replaceFiles);

// Commit 
myLibrary.Update();





希望这会有所帮助。



如需更多SharePoint帮助,请登录< a href =http://blog.sharepointclick.com> http://blog.sharepointclick.com


这篇关于如何以编程方式上载sharepoint 2010文档库中的文件和文件夹。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆