Click here to Skip to main content
13,258,269 members (51,182 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 ?
Posted 19-Mar-13 21:21pm
What do you mean by "check", exactly?
shinebudy 20-Mar-13 2:41am
I want to check Pages name(.aspx) in my forums if its exists than return msg already exists
Rate this: bad
Please Sign up or sign in to vote.

Solution 1


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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171114.1 | Last Updated 20 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100