Click here to Skip to main content
12,504,462 members (55,365 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET4
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 20:21pm
Comments
   
What do you mean by "check", exactly?
—SA
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
 
good
Please Sign up or sign in to vote.

Solution 1

HI,

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.
  Permalink  
Rate this: bad
 
good
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;
}
  Permalink  

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 | Mobile
Web02 | 2.8.160919.1 | Last Updated 20 Mar 2013
Copyright © CodeProject, 1999-2016
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