If you want to create a folder, you have to specify its name in the leafName parameter. change your code to :
foreach (SPListItem reparto in reparti.Items)
{
var folder = dl.Items.Add(
dl.RootFolder.ServerRelativeUrl,
SPFileSystemObjectType.Folder,
"Test"
);
folder.Update();
}
If it can help, here a small utility method I wrote to create a full folder hierarchy :
/// <summary>
/// Provide utilities methods related to folder management
/// </summary>
public static class SPFolderUtilities
{
/// <summary>
/// Ensures the specified folder exists.
/// </summary>
/// <param name="list">The list where to create the folder.</param>
/// <param name="subFolderPath">The sub folder path.</param>
/// <returns>
/// The existing <see cref="SPFolder"/> or a newly created if it did not exists.
/// </returns>
public static SPFolder EnsureFolder(SPList list, string subFolderPath)
{
Contract.Requires<ArgumentNullException>(list != null);
Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(subFolderPath));
if (!IO.SPPathUtilities.IsFileOrFolderNameValid(subFolderPath, true))
{
throw new ArgumentException("Invalid characters in the file or folder name", "subFolderPath");
}
var folderPaths = subFolderPath.Split('/');
var currentFolder = list.RootFolder;
for (int i = 0; i < folderPaths.Length; i++)
{
currentFolder = list.ParentWeb.GetFolder(currentFolder.Url); // hacky refresh
var subFolder = currentFolder.SubFolders.Cast<SPFolder>().FirstOrDefault(f => string.Compare(f.Name, folderPaths[i], true) == 0);
if (subFolder == null)
{
var newFolderItem = list.Items.Add(currentFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder, folderPaths[i]);
newFolderItem.SystemUpdate();
subFolder = newFolderItem.Folder;
}
currentFolder = subFolder;
}
return currentFolder;
}
}