Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is it possible to concatenate fields in the tree view control of sharepoint to show the folder ID and folder name together. Any help would be appreciated.

Regards

George Thomas
Posted
Comments
Gthomas 18-Feb-11 12:00pm    
Sandeep
I am working on a document library system where documents will be loaded. My client want to see the ID along with the folder name. If you can help me to find the solution.

Thanks in advance

Regards

George
Gthomas 18-Feb-11 12:09pm    
I am using the code:
using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using System.ComponentModel;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

namespace LibraryTree
{

[Guid("f77a9774-a3cb-4020-a9ff-01bf2485a29d")]
public class LibraryTree : Microsoft.SharePoint.WebPartPages.WebPart
{

public LibraryTree()
{
this.Title = "Document Library Tree View";
this.ExportMode = WebPartExportMode.All;
}

protected string _LibraryPath = "";
[Personalizable(PersonalizationScope.Shared),
Browsable(false),
Category("Document Library Selection")]
public string LibraryPath
{
get
{
return _LibraryPath;
}
set
{
_LibraryPath = value;
}
}

public override ToolPart[] GetToolParts()
{
List<toolpart> parts = new List<toolpart>();
PickerToolPart picker = new PickerToolPart();
parts.AddRange(base.GetToolParts());
picker.Items.Add(new PickerItem("Document Library To View:", "LibraryPath", PickerType.List));
picker.Title = "Document Library Selection";
parts.Add(picker);
return parts.ToArray();
}

protected override void CreateChildControls()
{
base.CreateChildControls();
SPWeb wb = SPContext.Current.Web;
string baseURL = wb.Url.ToString();
string _CorrectedLibraryPath;
try
{
if (_LibraryPath == "")
{
throw new Exception("No Document Library selected. Please select one from web part properties pane.");
}

//check if the library name was selected from picker or entered manually
if (_LibraryPath.Substring(0, 1) == "/")
{
_CorrectedLibraryPath = _LibraryPath.Substring(1);
}
else
{
_CorrectedLibraryPath = _LibraryPath;
}

SPDocumentLibrary doclib = (SPDocumentLibrary)wb.Lists[_CorrectedLibraryPath];

// A table for layout
Table tbl;
TableRow row;
TableCell cell;
tbl = new Table();
row = new TableRow();
cell = new TableCell();

// first row for title
cell.VerticalAlign = VerticalAlign.Middle;
cell.HorizontalAlign = HorizontalAlign.Left;
Label lblTitle = new Label();
lblTitle.Text = "Tree View of " + doclib.Title +":" ;
cell.Controls.Add(lblTitle);
row.Controls.Add(cell);
tbl.Controls.Add(row);

//second row for treeview
row = new TableRow();
cell = new TableCell();
cell.VerticalAlign = VerticalAlign.Middle;
cell.HorizontalAlign = HorizontalAlign.Left;
TreeView TreeView1 = new TreeView();
SPFolder root = doclib.RootFolder;
TreeNode node = new TreeNode();
node = Utility.GetFolderNode(node, root, baseURL);
node.Text = doclib.Title;
node.NavigateUrl = doclib.DefaultViewUrl;
long size = Utility.GetFolderSize(root) / 1024;
long numFiles = Utility.GetNumberOfFilesInFolder(root);
node.ToolTip = "Size:" + size.ToString() + " KBs " + " Files:" + nu

1 solution

Yes.

Either you can concatenate it while populating the nodes OR better option would be to get them concatenated from the database itself while retriving data.
 
Share this answer
 
Comments
Gthomas 19-Feb-11 10:21am    
Sandeep
If i want to concatenate while populating the tree view node.
folderinfo.Name = subFolder.Name;

Is the code correct:
folderinfo.Name = subFolder.Name+subfolder.ID;
Sandeep Mewara 19-Feb-11 10:24am    
Yep, I guess this should do if you are assigning node names manually.

If it's like assigning the source some field then it would not work - for that, it would be better if you go from query prospective as I said.
Sandeep Mewara 19-Feb-11 13:31pm    
Based on the code pasted above in comments, it looks like you are forming nodes at runtime and assiging the text to it. This way, appending the names should work. No need of query or any other change.
Gthomas 19-Feb-11 10:54am    
My document library is having one custom column called [Index ID]. On the view i am sorting based on the calculated column. I need to display the tree view on the site hierarchy showing the [Index ID] and Directory / File Names. Something like:
Library Name
1 George
2 Thomas

I would also like to know if it possible to make default.aspx as the view for all. Why i am asking is as soon i click the item in the tree view it takes me to AllItems.aspx page.

Thanks in advance.
Regards
George Thomas
Gthomas 19-Feb-11 11:16am    
Sandeep
If i want to use database what changes i will need to do on the tree view code. I am new to sharepoint so i don't have expertise knowledge. Any help would be appreciated.

Regards

George Thomas

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900