Click here to Skip to main content
15,892,517 members
Please Sign up or sign in to vote.
1.00/5 (1 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
Comments
Sergey Alexandrovich Kryukov 20-Mar-13 2:37am    
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

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.
 
Share this answer
 
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
C#
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;
}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900