Click here to Skip to main content
Sign Up to vote bad
good
See more: C#
Hi All,
 
I got an assignement to develop an application in C#.The application has the following functionality.
1>There will Be different folders ,Input files will be loaded at different time.
2>We have to check whether input file is present in a particular folder at particular time or not
Ex:Check the folder "X"every day at 5 PM,Check the folder "Y"every day at 6 PM,
 
I dont know how to start ..Could you please advice how to proceed this?
Posted 17 Dec '12 - 0:35


4 solutions

  Permalink  
Comments
Prashant Bangaluru - 17 Dec '12 - 21:31
Thanks Suresh..The First link is really help ful for me..Author explained it very clear and good manner..I want to add one more question here how do I check for files in different folder at different time...?Can I use an xml whill will tell at what time which folder to check etc..Please advice me on this also
  Permalink  
FileInfo file = new FileInfo(yourFullPathOfFile);
if(file.Exists)
{
     //yes, file exists
}
else
{
    //no, file does not exists
}
  Permalink  
1. Created a Sample XML file (XMLFile.xml)
 
<?xml version="1.0" encoding="utf-8" ?>
<Information>
  <FolderInfo>
    <Folder>c:\\SampleFolder\Folder_X</Folder>
    <Time>12/18/2012 2:17:25 PM</Time>
    <Files>
      <file>XFile1.doc</file>
      <file>XFile2.txt</file>
      <file>XFile3.png</file>
      <file>XFile4.zip</file>
    </Files>
  </FolderInfo>
  <FolderInfo>
    <Folder>c:\\SampleFolder\Folder_Y</Folder>
    <Time>12/18/2012 2:19:25 PM</Time>
    <Files>
      <file>YFile1.doc</file>
      <file>YFile2.txt</file>
      <file>YFile3.png</file>
      <file>YFile4.zip</file>
    </Files>
  </FolderInfo>
  <FolderInfo>
    <Folder>c:\\SampleFolder\Folder_Z</Folder>
    <Time>12/18/2012 2:18:25 PM</Time>
    <Files>
      <file>ZFile1.doc</file>
      <file>ZFile2.txt</file>
      <file>ZFile3.png</file>
      <file>ZFile4.zip</file>
    </Files>
  </FolderInfo>
</Information>
 
2. After creating your windows service then add this method in the main class
 
private void CheckFileInFolder()
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath("XMLFile.xml"));
 
XmlNode xnFolderInfo = xmlDoc.ChildNodes[1];
 
foreach (XmlNode xn in xnFolderInfo.ChildNodes)
{
string strFolder = xn.ChildNodes[0].InnerText;
DateTime dtTime = Convert.ToDateTime(xn.ChildNodes[1].InnerText);
if (DateTime.Now.ToString("dd/mm/yyyy hh:mm") == dtTime.ToString("dd/mm/yyyy hh:mm"))
{
foreach (XmlNode xnFiles in xn.ChildNodes[2])
{
string strFile = xnFiles.InnerText;
if (File.Exists(Path.Combine(strFolder, strFile)))
{
// Do Your Work here
}
}
}
}
}
 

Call this method on OnElapsedTime event
private void OnElapsedTime(object source, ElapsedEventArgs e)
{
  TraceService("Another entry at "+DateTime.Now);
  CheckFileInFolder()
}
 
Here DateTime.Now.ToString("dd/mm/yyyy hh:mm") == dtTime.ToString("dd/mm/yyyy hh:mm") is just a sample use your own condition here
 
you said that you need to Check the folder "X"every day at 5 PM,Check the folder "Y"every day at 6 PM
 
Take only the time in xml node instead of date and time.
 
<FolderInfo>
   <Folder>c:\\SampleFolder\Folder_X</Folder>
   <Time>2:17:25 PM</Time>
   <Files>
     <file>XFile1.doc</file>
     <file>XFile2.txt</file>
     <file>XFile3.png</file>
     <file>XFile4.zip</file>
   </Files>
 </FolderInfo>
 <FolderInfo>
   <Folder>c:\\SampleFolder\Folder_Y</Folder>
   <Time>2:19:25 PM</Time>
   <Files>
     <file>YFile1.doc</file>
     <file>YFile2.txt</file>
     <file>YFile3.png</file>
     <file>YFile4.zip</file>
   </Files>
 </FolderInfo>
 
DateTime dtTime = Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + xn.ChildNodes[1].InnerText);
            if (DateTime.Now.ToString("hh:mm") == dtTime.ToString("hh:mm"))
            {
  Permalink  
Comments
Prashant Bangaluru - 18 Dec '12 - 22:08
Thanks Suresh..I feel that I can start this assignement today only..thanks for giving inputs at right time.
SureshDasari1986 - 24 Dec '12 - 6:09
post your solution, after completion. it will help others.
Prashant Bangaluru - 9 Jan '13 - 4:37
Sorry Suresh.. The assignement is cancelled..But I ll do as a hobby assignement and post asap
Prashant Bangaluru - 20 Feb '13 - 1:41
Hi Suresh, Now I am trying same logic with console application .We made it to run every 5 mins but the problem is we are loading the xml every 5 mins.Can you please tell me how to load an xml daily only once.
SureshDasari1986 - 1 Mar '13 - 6:40
maintain the date into a static variable for first time, then check with that date every time.

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 243
1 Rohan Leuva 220
2 Sergey Alexandrovich Kryukov 208
3 Abhinav S 168
4 Mahesh Bailwal 165
0 Sergey Alexandrovich Kryukov 8,494
1 OriginalGriff 6,799
2 CPallini 3,603
3 Rohan Leuva 2,923
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid