Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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:35am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

  Permalink  
Comments
Prashant Bangaluru at 17-Dec-12 21:31pm
   
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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

FileInfo file = new FileInfo(yourFullPathOfFile);
if(file.Exists)
{
     //yes, file exists
}
else
{
    //no, file does not exists
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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  
v4
Comments
Prashant Bangaluru at 18-Dec-12 22:08pm
   
Thanks Suresh..I feel that I can start this assignement today only..thanks for giving inputs at right time.
SureshDasari1986 at 24-Dec-12 6:09am
   
post your solution, after completion.
it will help others.
Prashant Bangaluru at 9-Jan-13 4:37am
   
Sorry Suresh.. The assignement is cancelled..But I ll do as a hobby assignement and post asap
Prashant Bangaluru at 20-Feb-13 1:41am
   
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 at 1-Mar-13 6:40am
   
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
0 Sergey Alexandrovich Kryukov 530
1 mhegazy94 460
2 Ravi Bhavnani 230
3 Kornfeld Eliyahu Peter 185
4 Shemeemsha RA 160
0 Sergey Alexandrovich Kryukov 7,205
1 OriginalGriff 6,801
2 CPallini 5,350
3 George Jonsson 3,644
4 Gihan Liyanage 2,797


Advertise | Privacy | Mobile
Web02 | 2.8.140922.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2014
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