任何人都可以建議我在如何將文件上傳到共享點文檔庫上創建銀光沙盒解決方案。我是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. Sharepoint 2013將文件上傳到文檔庫文件大小
- 3. 使用HTTP將文件上傳到Sharepoint(WSS 3.0)文檔庫PUT
- 4. Office 365 Sharepoint將文件上傳到文檔庫
- 5. 如何創建按鈕將文檔上傳到文檔庫(Sharepoint 2010)
- 6. 如何生成html文件並將其上傳到sharepoint 2007文檔庫
- 7. 使用CronTab將文檔上傳到SharePoint
- 8. 將同名文檔上傳到SharePoint 2010
- 9. 上傳文件到SharePoint文檔庫的元數據
- 10. 使用csv文件將文檔上傳到Sharepoint站點
- 11. 無法將大文件(> 50MB)上載到SharePoint 2010文檔庫
- 12. 將文檔從Windows應用商店應用上傳到SharePoint 2013文檔庫
- 13. 一次可以將多少個文件上傳到SharePoint文檔庫?
- 14. 哪個Windows帳戶用於將文件上傳到SharePoint文檔庫?
- 15. 使用IRM將文檔上傳到SharePoint庫
- 16. 使用低級Web服務將文檔上傳到Sharepoint庫
- 17. 使用WebClient將文檔上載到SharePoint文檔庫中的特定文件夾
- 18. Sharepoint文檔庫文件
- 19. 如何使用Perl將文檔上傳到SharePoint?
- 20. 如何使用android將文檔上傳到SharePoint?
- 21. 如何使用Java將文檔上傳到SharePoint?
- 22. Sharepoint 2010上傳文檔
- 23. 上傳到文檔庫
- 24. 使用Powershell將文件上傳到SharePoint
- 25. 將REST文件上傳到Sharepoint DMS
- 26. 上傳文件到SharePoint Server
- 27. Sharepoint文檔庫
- 28. 將SharePoint文檔庫集成到ASP.NET中
- 29. 如何將Sharepoint文檔庫中的文檔返回給用戶?
- 30. Sensenet將文件上傳到文檔庫 - 字段填充
嗨夾具,thx答覆,但我得到的錯誤說:「文件操作不允許訪問路徑'C:\ aaa \ s.txt'被拒絕。 – Prageeth 2013-04-11 12:59:57
它似乎無法訪問目錄路徑。移動到您有完全控制訪問權限的特定文件夾中的文件。 – Jigs 2013-04-11 16:54:36