【问题标题】:SharePoint 2013 Upload file to folder in document librarySharePoint 2013 将文件上传到文档库中的文件夹
【发布时间】:2016-08-24 06:33:19
【问题描述】:

我有以下代码将文件放入文档库:

        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();
            }
        }
    }

我想将文件放在该库中名为“Nav”的文件夹中。我不知道如何做到这一点。我尝试过但无法将其放入文件夹中。

这是我最近的努力:

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

想法?

【问题讨论】:

    标签: sharepoint-2013


    【解决方案1】:

    这最终对我有用:

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

    看起来很乱,但它有效..所以我会活下去。

    【讨论】:

      猜你喜欢
      • 2010-09-23
      • 1970-01-01
      • 2019-02-21
      • 2013-10-08
      • 2010-10-02
      • 1970-01-01
      • 2010-10-01
      • 2013-12-12
      • 1970-01-01
      相关资源
      最近更新 更多