Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET4.0
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
Comments
Sergey Alexandrovich Kryukov at 20-Mar-13 2:37am
   
What do you mean by "check", exactly?
—SA
shinebudy at 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
0 /\jmot 240
1 Richard Deeming 195
2 Richard MacCutchan 190
3 Zoltán Zörgő 175
4 Peter Leow 160
0 Sergey Alexandrovich Kryukov 9,328
1 OriginalGriff 6,831
2 Peter Leow 4,477
3 Zoltán Zörgő 3,984
4 Richard MacCutchan 2,832


Advertise | Privacy | Mobile
Web04 | 2.8.150129.1 | Last Updated 20 Mar 2013
Copyright © CodeProject, 1999-2015
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