显示文件夹项目

时间:2013-10-08 09:50:44

标签: c# asp.net function directory

现在几天我在ASP.NET中遇到了一个项目问题。我应该设计一个网站:

  • 第一个:一个函数,它会检查项目中的文件夹是否是子文件夹bin,如果有两个特定文件中的任何一个,则在此bin文件夹中
  • 第二:一个功能(List),它只会在网站上显示具有第一个功能条件的文件夹

现在问题。在一些帮助下,我设法编写代码(我是ASP.NET btw的新手)。这是代码:

这里是aspx代码:

<%@ Page Language="C#" AutoEventWireup="True" CodeBehind="Home.aspx.cs" Inherits="TestSite.Home" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>
    <link href="Layout.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:ListView ID="listView" runat="server"> 
        <ItemTemplate> 
            <asp:Label ID="Label1" Text="<%#Container.DataItem %>" runat="server" /> 
        </ItemTemplate> 
    </asp:ListView>
</div>
</form>
</body>
</html>

这是aspx.cs代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace TestSite
{
public partial class WorkingwithDirectory : System.Web.UI.Page
{           
    List<string> results = new List<string>();

    public bool IsApplicationDirectory( string directory )
    {
        if ( Directory.Exists(Server.MapPath("~/../bin")) ) {
            if ( File.Exists(Server.MapPath("~/../bin/Portal.Server.dll")) || File.Exists(Server.MapPath("~/../bin/Host.Server.dll")) ) {
                return true;
            }
            else {
                return false;
            }
        }
        else {
            return false;
        }
    }

    public List<string> GetApplicationDirectories()
    {


        DirectoryInfo dir = new DirectoryInfo(Server.MapPath("~/"));
        foreach (DirectoryInfo di in dir.GetDirectories())
        {
            if ( IsApplicationDirectory( dir.FullName ) ) 
            {
                results.Add(dir.FullName);
            }
        }
        return results;
    }

    protected void Page_Load( object sender, EventArgs e )
    {

        if ( !Page.IsPostBack ) 
        {
            List<string> appDirectories = GetApplicationDirectories();

            --> listView.DataSource = appDirectories;
            --> listView.DataBind();
        }
    }
}

}

问题:上面的aspx.cs文件(我给出了箭头)我得到一个错误告诉我:“名称'listView'在当前上下文中不存在”

我尝试了一些解决方案,但不幸的是没有一个主题有效。我会更感谢你的帮助。

1 个答案:

答案 0 :(得分:0)

重命名

public partial class WorkingwithDirectory : System.Web.UI.Page

public partial class Home : System.Web.UI.Page
相关问题