任何人都可以建议我在如何将文件上传到共享点文档库上创建银光沙盒解决方案。我是C#开发人员。如何将文件上传到SharePoint文档库
4
A
回答
2
你可以参考下面的代码:
String UploadFile = @"C:\YourFile.txt";
String sharePointWebAdd = "http://yoursite.com/sites/Research/";
String docLib = "Shared Documents";
using (SPSite oSite = new SPSite(sharePointWebAdd))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
if (!System.IO.File.Exists(UploadFile))
throw new FileNotFoundException("File not found.", UploadFile);
SPFolder myLibrary = oWeb.Folders[docLib];
// Prepare to upload
Boolean replaceExistingFiles = true;
String fileName = System.IO.Path.GetFileName(UploadFile);
FileStream fileStream = File.OpenRead(UploadFile);
// Upload document
SPFile spfile = myLibrary.Files.Add(fileName, fileStream, replaceExistingFiles);
// Commit
myLibrary.Update();
}
}
另请参考:
2
一点很难在这里描述了。但我认为你会从文件中获得FileInfo。对于银光应用程序,您需要添加两个客户端对象模型的引用dll。
Microsoft.SharePoint.Client.Silverlight.dll.
Microsoft.SharePoint.Client.Silverlight.Runtime.dll.
你可以从C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin
目录路径找到上面的dll。
private ClientContext context;
private Web web;
private void UploadFile(FileInfo fileToUpload, string libraryTitle, string subfolderPath, bool fileOverwrite)
{
try
{
//Treatment of files and loading it to byte array []
Stream str = null;
Int32 strLen, strRead;
str = fileToUpload.OpenRead();
strLen = Convert.ToInt32(str.Length);
byte[] strArr = new byte[strLen];
strRead = str.Read(strArr, 0, strLen);
using (context = new ClientContext("http://localhost/"))
{
web = context.Web;
//Defining where to find the files to tape record the library go
List destinationList = web.Lists.GetByTitle(libraryTitle);
//Creating a file
var fciFileToUpload = new FileCreationInformation();
fciFileToUpload.Content = strArr;
//Must determine whether to upload files directly to the library or whether to upload the files to sub directories and stack your way to the file
string uploadLocation = fileToUpload.Name;
if (!string.IsNullOrEmpty(subfolderPath))
{
uploadLocation = string.Format("{0}/{1}", subfolderPath, uploadLocation);
}
uploadLocation = string.Format("{0}/{1}/{2}", webUrl, libraryTitle, uploadLocation);
//Sets the path to the file where you want to upload and subor whether to overwrite the file or not
fciFileToUpload.Url = uploadLocation;
fciFileToUpload.Overwrite = fileOverwrite;
clFileToUpload = destinationList.RootFolder.Files.Add(fciFileToUpload);
//load web,list.
context.Load(web);
context.Load(destinationList, list => list.ItemCount);
context.Load(clFileToUpload);
context.Load(clFileToUpload.ListItemAllFields);
context.ExecuteQueryAsync(OnLoadingSucceeded, OnLoadingFailed);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
unhideComponents();
}
}
private void OnLoadingSucceeded(Object sender, ClientRequestSucceededEventArgs args)
{
Dispatcher.BeginInvoke(fileUploaded); // fileUploaded is function
}
private void OnLoadingFailed(object sender, ClientRequestFailedEventArgs args)
{
Dispatcher.BeginInvoke(fileNotUploaded); //fileNotUploaded is function
}
相关问题
- 1. 如何将文件上传到SharePoint中的文档库?
- 2. 使用HTTP将文件上传到Sharepoint(WSS 3.0)文档库PUT
- 3. 将同名文档上传到SharePoint 2010
- 4. 使用CronTab将文档上传到SharePoint
- 5. 上传文件到SharePoint文档库的元数据
- 6. 使用csv文件将文档上传到Sharepoint站点
- 7. 哪个Windows帐户用于将文件上传到SharePoint文档库?
- 8. 一次可以将多少个文件上传到SharePoint文档库?
- 9. 使用低级Web服务将文档上传到Sharepoint库
- 10. 使用IRM将文档上传到SharePoint库
- 11. 使用WebClient将文档上载到SharePoint文档库中的特定文件夹
- 12. 如何使用Perl将文档上传到SharePoint?
- 13. 如何使用Java将文档上传到SharePoint?
- 14. Sharepoint 2010上传文档
- 15. 上传到文档库
- 16. 使用Powershell将文件上传到SharePoint
- 17. 上传文件到SharePoint Server
- 18. Sharepoint文档库
- 19. 将SharePoint文档库集成到ASP.NET中
- 20. 将文件上传/同步到文档库
- 21. Sensenet将文件上传到文档库 - 字段填充
- 22. 如何将Sharepoint文档库中的文档返回给用户?
- 23. 需要将文档上传到MOSS文档库的系统
- 24. 如何通过Google Data API将文件上传到Google文档?
- 25. 如何将文档从网络表单上传到Google文档?
- 26. 将上传更改为SharePoint 2010中的其他文档库
- 27. 如何使用Silverlight和客户端Web服务将文件上传到Sharepoint文档库?
- 28. 将文件复制到SharePoint中的文档库中
- 29. Sharepoint 2010:将文件复制或添加到文档库
- 30. Sharepoint文件上传
嗨夹具,thx答复,但我得到的错误说:“文件操作不允许访问路径'C:\ aaa \ s.txt'被拒绝。 – Prageeth 2013-04-11 12:59:57
它似乎无法访问目录路径。移动到您有完全控制访问权限的特定文件夹中的文件。 – Jigs 2013-04-11 16:54:36