I have been running into a javascript error when I use the Box, Inc c# sdk to create multiple folders at once. I have been using a class consisting of a path and a list of strings for the paths of the child directories. When I call the CreateBoxFolders method however, it randomly throws a parameter count mismatch exception. I’ve so far been unable to determine why.
private void CreateBoxFolders(string dir, long boxfolderid)
{
string[] dirnames = dir.Path.Split('\\');
CreateBoxFolder(dirnames[dirnames.Count() - 1], boxfolderid);
long id = GetFolderId(dirnames[dirnames.Count() - 1], boxfolderid);
// This is a class with a list that stores the folder structure and path
dir.ChildDirectories.ForEach(x =>
CreateBoxFolders(x, id));
}
private void CreateBoxFolder(string name, long parent)
{
_BoxManager.CreateFolder(name, parent, false);
}
private long GetFolderId(string name, long parent)
{
var folders = _BoxManager.GetFolderStructure(parent,
BoxSync.Core.Primitives.RetrieveFolderStructureOptions.OneLevel);
long number = folders.Folder.Folders.Where(x => x.Name == name.Trim()).First().ID;
return number;
}
I suspect that one of your arrays is either null or empty.
This line is likely at some point working with the root folder, where the id=0. Folder 0 is a virtual folder that sits at the root of your account and doesn’t have any directory structure. Thus it is the root. My suspicion (without being a C# programmer) is that this is evaluating down to
I suspect that the count of an empty array may be either null or zero. Null would be bad…