的SharePoint 2013服务器上传文件到文件库文件夹

问题描述:

我有下面的代码放在一个文件,在文档库中:的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"]; 

想法?

这结束了对我的工作:

   SPFolder myLibrary = oWeb.Folders[documentLibraryName]; 
       SPFolder subFolder = myLibrary.SubFolders["Nav"]; 

似乎混乱,但它的工作原理..所以我会活。