bryan-bit-wizards
-
1/7/2009 2:21:49 PM
RE:Create Multiple Folders
Thank you for your help. Using the documentation, I was able to programmatically add the foider.
This code will create the main folder and 2 subfolders for every record returned by the query.
Code:
string strName = ""; GeneralConnection cn = new GeneralConnection(); DataSet ds = null; object[,] parameters = new object[1, 3]; parameters[0, 0] = ""; parameters[0, 1] = ""; ds = cn.ExecuteQuery("[Query Name]", parameters); if (ds.Tables[0].Rows.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { strName = dr[3].ToString();
// create tree provider instance CMS.TreeEngine.TreeProvider provider = new CMS.TreeEngine.TreeProvider(CMS.CMSHelper.CMSContext.CurrentUser);
// get parent node for new document CMS.TreeEngine.TreeNode parent = provider.SelectSingleNode(CMS.CMSHelper.CMSContext.CurrentSite.SiteName, "/Images/[Folder Name]", "en-us");
// create a new tree node CMS.TreeEngine.TreeNode node = new CMS.TreeEngine.TreeNode("CMS.Folder", provider);
if (parent != null) { //Create the main folder // set document properties node.NodeName = strName; node.NodeAlias = strName; node.SetValue("DocumentName", strName); node.SetValue("DocumentCulture", "en-us"); // create New document node.Insert(parent.NodeID);
//Create Subfolders //Index // create a new tree node CMS.TreeEngine.TreeNode nodeIndex = new CMS.TreeEngine.TreeNode("CMS.Folder", provider); // set document properties nodeIndex.NodeName = "Index"; nodeIndex.NodeAlias = "Index"; nodeIndex.SetValue("DocumentName", "Index"); nodeIndex.SetValue("DocumentCulture", "en-us"); // create New document nodeIndex.Insert(node.NodeID);
//Images // create a new tree node CMS.TreeEngine.TreeNode nodeImages = new CMS.TreeEngine.TreeNode("CMS.Folder", provider); // set document properties nodeImages.NodeName = "Images"; nodeImages.NodeAlias = "Images"; nodeImages.SetValue("DocumentName", "Images"); nodeImages.SetValue("DocumentCulture", "en-us"); // create New document nodeImages.Insert(node.NodeID); } } }
-Bryan
|