如何检查asp.net中的现有页面名称? [英] How to check existing Pages name in asp.net?

查看:48
本文介绍了如何检查asp.net中的现有页面名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,



我创建一个页面需要检查aspx页面,如果在我的项目中,如果test.aspx比函数检查已经存在在项目中我该怎么做?

hello friends,

I make one page Whose one filed required to check for aspx page like if in my project if test.aspx than function check for already exist in project how can i do that ?

推荐答案

HI,



你可以使用Directory.GetFiles方法。请查看以下MSDN文章。

MSDN-Directory.GetFiles [ ^ ]并传递Server.MapPath()作为文章中讨论的目录路径。



希望它有所帮助。


you can make use of "Directory.GetFiles" method. check out below MSDN article.
MSDN-Directory.GetFiles[^] and pass "Server.MapPath()" as a directory path as discussed in the article.

hope it helps.


如果您需要检查项目/网站中是否存在特定的aspx文件,那么首先必须获取根目录物理文件。之后,您可以使用Directory对象检查文件是否存在。代码示例如

If you need to check a particular aspx file is exists or not in your project/web site then first you have to get the root directory physical file. After that you can check it with Directory object that the file is exists or not. The code example like
protected void Page_Load(object sender, EventArgs e)
{
     bool found = IsFileExists("abc.aspx");
}
private bool IsFileExists(string fileName)
{
    string rootWebDirectory = Server.MapPath("rootwebdirectory");
    string[] files = System.IO.Directory.GetFiles(rootWebDirectory, fileName, SearchOption.AllDirectories);
    return files != null && files.Count() > 0;
}


这篇关于如何检查asp.net中的现有页面名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆