Parse IIS Document root through ASP.NET and get Last Modified date of the files -


i using asp.net

my task loop through folders , files of document root c:\inetpub\wwwroot find .aspx files have been modified during last 7 days => grab value of "title" node files => output value of "title" , last modified date.

any direction code samples appreciated.

thanks hayk.

here solution wrote above question:

using system.collections; using system.collections.specialized; using system.xml; using system.globalization; using system.io;  using system.net; using system.configuration; using system.data; using system.data.sqlclient; using system.web; using system.web.security; using system.web.ui; using system.web.ui.htmlcontrols; using system.web.ui.webcontrols; using system.web.ui.webcontrols.webparts; using system.linq; using system.xml.linq; using system.collections.generic; using system.text.regularexpressions;  public partial class directoryiterator : system.web.ui.page  {       public void generatelinks(string webpath, int linkcount)     {         datetime now1 = datetime.now;          string webpathnoslash = webpath.substring(1);          string path = server.mappath(webpathnoslash);          try          {                      if(directory.exists(path))                 {                           //string[] dirs1 = directory.getfiles(path, "*.aspx", searchoption.alldirectories);               var dirs2 = new directoryinfo(path).getfiles("*.aspx", searchoption.alldirectories).orderbydescending(f => f.lastwritetime).select(f => f.fullname).tolist();                   string[] dirs1 = dirs2.toarray();                   //array.sort(dirs1);                     if(dirs1 == null || dirs1.length == 0)                {                 response.write("there no .aspx files in specified directory");                              }               response.write("<ul>");                         foreach (string dir1 in dirs1.take(linkcount))              {                                                                                               if (now1.subtract(system.io.file.getlastwritetime(dir1)).totalminutes < 10080)                   {                   string absoluteurl1 = dir1.substring(19);  //28                                                          string absoluteurl2 = absoluteurl1.replace(@"\", @"/");                    string html1 = file.readalltext(dir1);                   match m1 = regex.match(html1, @"<title>\s*(.+?)\s*</title>");                        if (m1.success)                        {                                                     // response.write (m1.groups[1].value);                                                    string link1 = "<a href=\'" +absoluteurl2+ "\'>" + m1.groups[1].value + "</a>";                                                     response.write("<li>");                               response.write(link1);                            response.write("&nbsp;");                            response.write("(");                             response.write(system.io.file.getlastwritetime(dir1).date.tostring("mm-dd-yyyy"));                            response.write(")");                           response.write("&nbsp;");                                                                    if (system.io.file.getlastwritetime(dir1).date.tostring("mm-dd-yyyy") == datetime.today.tostring("mm-dd-yyyy"))                           {                                                     response.write("&nbsp;");                           response.write("<img src='/_resources/images/new.gif' alt='new' />");                                                       }                        response.write("</li>");                                                   }                        else                        {                            response.write("page title should not empty");                        }                    } //end if dates                   else                   {                                    response.write("<li>");                             response.write("no links matching criteria");                    response.write("</li>");                                                  }                   // end else dates              } //end foreach             response.write("</ul>");            } // end directory exists if                else              {                response.write("the specified directory not exist");              }               // end directory exists else          } //end try         catch (exception e)          {             response.write("the process failed: ");             response.write(e.tostring());         }     } }    

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -