Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5847069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:39:58+00:00 2026-05-22T12:39:58+00:00

In my application,I want to display some static files(.html,.htm,.txt) which will be uploaded by

  • 0

In my application,I want to display some static files(.html,.htm,.txt) which will be uploaded by the user(the admin),then I put them in a specified directory.

Also,the admin can add new folder or files to the directory,so I think using the asp:treeview to display the file list is a good idea,and I found this :

http://mattberseth.com/blog/2007/07/hwo_to_create_an_aspnet_ajax_s.html

enter image description here

The tree view in the left is what I want even it just read the folders and list the in the tree,so I made some fix to list both folders and files,also I make the tree can be edited:

The rule.aspx

<form id="form" runat="server">
    <div>
                <table id="tbl" cellpadding="0px" cellspacing="0px">            
                    <tr>
                        <td style="border:solid 1px black" valign="top">
                            <div style="overflow:auto;width:300px;height:450px;">
                                <asp:TreeView 
                                    ID="tvFolders" runat="server" 
                                    OnSelectedNodeChanged="TvFolders_SelectedNodeChanged">
                                    <NodeStyle 
                                        ImageUrl="Img/folder.gif" HorizontalPadding="3px" 
                                        Font-Underline="false" ForeColor="black" />
                                    <SelectedNodeStyle 
                                        Font-Underline="true" Font-Bold="true" />
                                </asp:TreeView> 
                            </div>
                        </td>
                    </tr>
                </table>         
        <br /> 
    </div>
    <!-- The tree editor controls -->
    <div id="addFold" runat="server"></div>
    <div id="addFile" runat="server"></div>
    <div id="deleteFile" runat="server"></div>
    <div id="deleteFold" runat="server"></div>


    <!-- Div used to show the content of the file -->
    <div id="contentDiv" runat="server"></div>
</form>

The rule.aspx.cs:

private DbService db=new DbService();
private bool isAdmin;
protected void Page_Load(object sender, EventArgs e)
{
    isAdmin=db.isUserAdmin(Context.Identify.user.name);

    if (!this.IsPostBack)
    {
        string rootFolder = this.Server.MapPath("files/");

        TreeNode rootNode = new TreeNode("Root", rootFolder);
        rootNode.Expanded = true;
        rootNode.Select();
        this.tvFolders.Nodes.Add(rootNode);

        BindDirs(rootFolder, rootNode);

        //set the editor button display or not according the type of current user
        setEditorVisibility();
    }
}

private void setEditorVisibility(){
    //if user select the directory,and he is the admin,so he can add fold/file under this directory,or delete this fold.
    addFold.visibile=deleteFold.visibile=addFile.visibile=isAdmin && Directory.Exist(ootNode.selectedNode.value);

    // if user select the file,and he is the admin,he can delte/update it.
    deleteFile.visibe=isAdmin && File.Exist(ootNode.selectedNode.value);
}
protected void TvFolders_SelectedNodeChanged(object sender, EventArgs args)
{
    setEditorVisibility();

    //now show the content in the contentDiv of the page
    if(File.Exist(ootNode.selectedNode.value)){
        this.contentDiv.innerHtml=xxxx? 
        //here how to make the content of the file displayed in the div?
        //I am sure the type of the file will be .html .htm or .txt.
    }
}

private static void BindDirs(string path, TreeNode treeNode)
{
    if (!string.IsNullOrEmpty(path))
    {
        foreach (string directoryPath in System.IO.Directory.GetDirectories(path))
        {
            System.IO.DirectoryInfo directory = new System.IO.DirectoryInfo(directoryPath);
            TreeNode subNode = new TreeNode(directory.Name, directory.FullName);
            treeNode.ChildNodes.Add(subNode);

            // bind sub directories
            BindDirs(directoryPath, subNode);
        }

        //add the file in the tree list
        foreach (string filePath in File.getFiles(path))
        {
            FileInfo info = new FileInfo(filePath);
            TreeNode subNode = new TreeNode(info.Name, info.FullName);
            treeNode.ChildNodes.Add(subNode);
        }
    }
}   

Now I just do not know how to display the file content when user select a node which is binded to a file.

ANy suggestion?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:39:59+00:00Added an answer on May 22, 2026 at 12:39 pm

    How About:

    this.contentDiv.innerHtml=File.ReadAllText(ootNode.selectedNode.value);
    

    EDIT
    The above will bring back normal line endings instead of html line endings if it’s a text file, so you can do below for text files:

    this.contentDiv.innerHtml=File.ReadAllText(ootNode.selectedNode.value).Replace("\r\n","</br>").Replace("\r","</br>").Replace("\n","</br>");
    

    Obviously still needs exception handling

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .net (3.5) WinForms application and want to display some html on
I am writing an application for Windows Mobile where I want to display some
I am working on a windows application where i want to display orkut user
I want to display an HTML formatted content in my application preferably inside a
In my Delphi program I want to display some information generated by the application.
In my application I want to display some pictures (I need to have them
I am using a static grouped UITableView to display some settings to the user.
I want an application which displays the some file properties of a mediafile if
I want to display some dynamic charts/graphs in my web application. The current good
I want to display some text for a few seconds and then quit my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.