Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP.Net树视图的SelectedNodeChanged未启动_Asp.net_C# 4.0 - Fatal编程技术网

ASP.Net树视图的SelectedNodeChanged未启动

ASP.Net树视图的SelectedNodeChanged未启动,asp.net,c#-4.0,Asp.net,C# 4.0,我是Treeview的新手。我想在树状视图中显示本地目录中的日志文件,然后单击它,该文件应该会打开。下面是我的代码: 1) 我的aspx页面: <asp:TreeView ID="tvLogResults" runat="server" ExpandDepth="1" OnSelectedNodeChanged="tvLogResults_SelectedNodeChanged" style="margin-left: 33px; margin-top: 16px;">

我是Treeview的新手。我想在树状视图中显示本地目录中的日志文件,然后单击它,该文件应该会打开。下面是我的代码:

1) 我的aspx页面:

<asp:TreeView ID="tvLogResults" runat="server" ExpandDepth="1" OnSelectedNodeChanged="tvLogResults_SelectedNodeChanged" style="margin-left: 33px; margin-top: 16px;">
                        <HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
                        <NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black" HorizontalPadding="0px"
                            NodeSpacing="0px" VerticalPadding="0px" />
                            <ParentNodeStyle Font-Bold="False" />
                            <RootNodeStyle ImageUrl="~/Styles/imgs/open-folder.jpg" />
                            <SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" HorizontalPadding="0px" VerticalPadding="0px" />
                        </asp:TreeView>

2) 代码隐藏

protected void btnSearch_Click(object sender, EventArgs e)
    {
        TreeNode n = new TreeNode();
        n.Value = "0";
        n.Text = "LogFiles-Datewise";
        n.SelectAction = TreeNodeSelectAction.Select;
        tvLogResults.Nodes.Add(n);


        string data = txtFromDate.Text;
        DateTime fromDate = DateTime.ParseExact(data, "MM/dd/yyyy", null);

        DateTime toDate = DateTime.Parse(txtToDate.Text);

        string path = string.Concat(HttpRuntime.AppDomainAppPath, @"LogFiles");



        var files = from c in currDirectory.GetFiles()
                    where c.CreationTime >= fromDate && c.CreationTime <= toDate
                    select c;
        int i = 1;
        foreach (FileInfo file in files)
        {
            DateTime lastAccessTime = file.LastAccessTime;
            TreeNode child = new TreeNode();
            child.Value = file.FullName;
            child.Text = lastAccessTime.ToString("MM/dd/yyyy");
            child.PopulateOnDemand = true;
            child.NavigateUrl = file.FullName;
            child.SelectAction = TreeNodeSelectAction.Select;
            tvLogResults.Nodes[0].ChildNodes.Add(child);
            i++;
        }
    }

    protected void tvLogResults_SelectedNodeChanged(object sender, EventArgs e)
    {
        string filename = Server.MapPath(tvLogResults.SelectedValue);

        System.IO.FileInfo file = new System.IO.FileInfo(filename);

        if (file.Exists)
        {
            System.Diagnostics.Process.Start(file.FullName);
        }
    }
protectedvoidbtnsearch\u单击(对象发送方,事件参数e)
{
TreeNode n=新的TreeNode();
n、 Value=“0”;
n、 Text=“LogFiles Datewise”;
n、 SelectAction=treeNodeAction.Select;
tvLogResults.Nodes.Add(n);
字符串数据=txtFromDate.Text;
DateTime fromDate=DateTime.ParseExact(数据“MM/dd/yyyy”,空);
DateTime toDate=DateTime.Parse(txtToDate.Text);
string path=string.Concat(HttpRuntime.AppDomainAppPath,@“日志文件”);
var files=来自currDirectory.GetFiles()中的c

其中c.CreationTime>=fromDate&&c.CreationTime这些是指向本地文件的无效URL

参考:

对于网络位置:

file://hostname/path/to/the%20file.txt

或者对于本地文件,省略主机名,但不省略斜杠 (请注意第三条斜线):

file:///c:/path/to/the%20file.txt


希望能为您解决此问题。

您确定要使用本地文件系统打开以
文件:\\\
开头的文件路径吗?您是否尝试过不使用
文件:\\\
?另外,如果您不知道,ASP.NET正在服务器上运行。如果您尝试访问的文件是运行浏览器的计算机上的本地文件,然后您将无法加载它…相反,您必须允许用户手动选择文件并上载以进行处理我的直觉是对文件位置的误解(客户端和服务器)根据我在OPYes下的评论,最好通过IIS提供文件,而不是在计算机上本地打开它们。但是我们不知道OP试图解决什么情况。我之前错了。很抱歉,完整路径显示为file:///C:/TraceFiles/LogFiles/Log11Nov.txt"仅限。即使我已更改到不同的驱动器和不同的位置,仍然没有发生任何事情。事件“OnSelectedNodeChanged”根本没有触发。单击节点时是否要添加其他事件?是否每次加载页面时都绑定树?为了从不同的位置读取,我将文件手动放入应用程序中然后什么也没有发生。然后我发布到IIS并尝试,没有结果。url,“file:///C:/TraceFiles/LogFiles/Log11Nov.txt当鼠标悬停在子节点上时显示,但未打开文件。