0
我有下面的代碼放在一個文件,在文檔庫中:的SharePoint 2013服務器上傳文件到文件庫文件夾
public static void UploadFile(string siteURL, string libraryName, string file)
{
String fileToUpload = file;
String sharePointSite = siteURL;
String documentLibraryName = libraryName;
using (SPSite oSite = new SPSite(sharePointSite))
{
using (SPWeb oWeb = oSite.RootWeb)
{
if (!System.IO.File.Exists(fileToUpload))
throw new FileNotFoundException("File not found.", fileToUpload);
SPFolder myLibrary = oWeb.Folders[documentLibraryName];
// Prepare to upload
Boolean replaceExistingFiles = true;
String fileName = System.IO.Path.GetFileName(fileToUpload);
FileStream fileStream = System.IO.File.OpenRead(fileToUpload);
// Upload document
SPFile spfile = myLibrary.Files.Add(fileName, fileStream, replaceExistingFiles);
// Commit
myLibrary.Update();
}
}
}
我想將文件放置在該庫被稱爲「導航」的文件夾內我不知道如何做到這一點..我已經嘗試過,但無法將其放入文件夾。
這是我的最新努力:
SPFolder myLibrary = oWeb.Folders[documentLibraryName].SubFolders["Nav"];
想法?