3

Trying to recurse through a folder and checkout or checkin all files. But i keep getting a DirectoryNotFoundException on the checkin. Oddly enough, i manually uploaded a file to the Agency folder (the root of our recurse) and that file works perfectly. The other folders / files in the Agency folder were put there by a feature and we just want to make sure all files are checked in.

        static void Main(string[] args) {
        string url = "http://site.sp2013.dev";

        using (SPSite site = new SPSite(url)) {
            using (SPWeb web = site.OpenWeb()) {

                var folder = web.GetFolder("Style Library/Agency");

                RecurseFolder(folder);
            }
        Console.ReadLine();
    }

    static void RecurseFolder(SPFolder folder) {
        Console.WriteLine("+ {0}", folder.Name);

        foreach(SPFile file in folder.Files) {
            if(file.CheckOutType != SPFile.SPCheckOutType.None) {

                file.CheckIn("asdf");
            } else {
                file.CheckOut();
                file.CheckIn("asdf");
            }

            Console.WriteLine("{0} : {1}", file.Name, file.CheckOutType);
         }

        foreach(SPFolder subFolder in folder.SubFolders) {
            RecurseFolder(subFolder);
        }

    }

as soon as i hit file.CheckIn("asdf"); i get

An unhandled exception of type 'System.IO.DirectoryNotFoundException' occurred in Microsoft.SharePoint.dll

Additional information: <nativehr>0x80070003</nativehr><nativestack></nativestack>There is no file with URL 'Style Library/Agency/css/ie8-grid-foundation-4.css' in this Web.

Is there something special about files deployed via a feature that will keep them from being updated via the SSOM by chance?

2
  • Note: CSOM = Client-Side Object Model, while you're apparently using the Server-Side Object Model.
    – Evariste
    Jun 10, 2017 at 16:21
  • oi, fixed it in an edit
    – dev null
    Jun 10, 2017 at 17:40

1 Answer 1

5

Maybe your module files are not deployed as GhostableInLibrary (see e.g. here for a definition of GhostableInLibrary vs Ghostable).
Would you share the code your XML element (module) that deploys the files into the library? GhostableInLibrary must be explicitely set on the Type attribute of each File node.

EDIT:
The problem was not about the GhostableInLibrary type of the file as per OP.
However, OP confirmed the module was deployed as a sandbox solution. When deployed from a sandbox solution, provisioned files are not automatically published (while they are with a farm/full-trust WSP), they stay in checked-out state, and they're checked-out to the user who activated the sandbox.
Beside that, there's something weird with the file C# API, something I already came accros once or twice: folder.Files lists all files even those that have no checked-in version (files that are normally visible only by the user who uploaded them), but the SPFile object it returns is set to Exists=false.

3
  • So i read through your link and i these are all deployed as ghostableinlibrary. here is the xml for that specific file that the exception is being thrown for. <File Path="Style Library\Agency\css\ie8-grid-foundation-4.css" Url="css/ie8-grid-foundation-4.css" Type="GhostableInLibrary" />
    – dev null
    Jun 10, 2017 at 17:56
  • Is it a sandbox solution or a farm (full-trust) solution?
    – Evariste
    Jun 10, 2017 at 18:37
  • Yes! it was a sandboxed solution ... when i changed it and redeployed i was able to get it to use the file.checkin method. Thanks so much for your help. Maybe you should edit your answer to also include a tidbit about sandboxed solutions?
    – dev null
    Jun 10, 2017 at 20:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.