How to get the values into text boxes from asp:treeview link?

Raki 456 Reputation points


i am working on a web application where using ASP:treeview control to display files link so that user can click and get the values into respective textboxes. my link file name format is "001193 - La Cabana - Ins Boiler and Machinery - 03-29-2023.pdf". so i have four text boxes to contain values from the link as soon as user click the link. so far i was able to manage populate three values into text boxes except Date value. For me only first two digit(03) getting not whole date. what i need to tweak to get the whole date into text box? Below is the code.


<asp:TreeView ID="TreeView1" runat="server" _ImageSet="XPFileExplorer" NodeIndent="15" OnSelectedNodeChanged="TreeView1_SelectedNodeChanged">
                            <HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" />
                            <NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black" HorizontalPadding="2px"
                                NodeSpacing="0px" VerticalPadding="2px"></NodeStyle>
                            <ParentNodeStyle Font-Bold="true" />
                            <SelectedNodeStyle BackColor="#B5B5B5" Font-Underline="False" HorizontalPadding="0px"
                                VerticalPadding="0px" />

 protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
                String filename = ((System.Web.UI.WebControls.TreeView)sender).SelectedValue;

                TreeNode selectedNode = TreeView1.SelectedNode;
                string[] fileNameParts = selectedNode.Text.Split('-');

                string projectNumber = fileNameParts[0].Trim();
                string projectName = fileNameParts[1].Trim();
                string insuranceType = fileNameParts[2].Trim();
                string fileDate = fileNameParts[3].Trim().Replace(".pdf", "");

                //string projectNumber = selectedNode.Text.Split('-')[0].Trim();
                //string projectName = selectedNode.Text.Split('-')[1].Trim();
                //string insuranceType = selectedNode.Text.Split('-')[2].Trim();
                //string[] nodeTextparts2 = nodeTextParts[3].Split('.');
                //string datePattern = @"\d{2}/\d{2}/\d{4}";
                //string date = "";
                //foreach (string part in nodeTextparts)
                //    Match match = Regex.Match(part.Trim(), datePattern);
                //    if (match.Success)
                //    {
                //        date = match.Value;
                //        break;
                //    }
                //string effectiveDate = filename[3].ToString();
                //string FinaleffectiveDate = nodeTextparts2[0].ToString();
                String rootDirectory = AppDomain.CurrentDomain.BaseDirectory;

                String relativePath = filename.Replace(rootDirectory, "");

                RadPdfViewer1.PdfjsProcessingSettings.File = relativePath;
                RadPdfViewer1.Visible = true;

                // Fill up text boxes values from the link 
                rad_txtProjectNumber.Text = projectNumber;
                rad_txtprojectName.Text = projectName;
                rad_txtInsuranceType.Text = insuranceType;
                rad_txtEffectivedate.Text = fileDate;
            catch (Exception ex)
                //lblerror.Text = ex.Message;
                //lblerror.Visible = true;

A set of technologies in the .NET Framework for building web applications and XML web services.
1,322 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
7,548 questions
No comments
{count} votes

Accepted answer
  1. XuDong Peng-MSFT 4,746 Reputation points Microsoft Vendor

    Hi @Raki,

    If you just want to get whole date string from SelectNode Text. You can try these code below:

    string NodeText = selectedNode.Text;
    string pattern = @"\b\d{2}-\d{2}-\d{4}\b";
    Match match = Regex.Match(NodeText, pattern);
    if (match.Success) { 
         string fileDate = match.Value;


    User's image

    Best regards,

    Xudong Peng

    If the answer is the right solution, please click "Accept Answer" and kindly upvote. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

0 additional answers

Sort by: Most helpful