0

Hi I want to create an application that connect to my host and check if any new file added in the the directories. so I need the creation time of that host file but i could not connect to the server. I just find some code for creation time of server files but i don't know why they don't work some how. any suggestion?

this is the code:

        string path = "http://neginmelk.ir/app_test\t2/mine.txt";
        if (!File.Exists(path)) 
        {
            File.Create(path);
        } 
        else 
        {
            // Take an action that will affect the write time.
            File.SetLastWriteTime(path, new DateTime(1985,4,3));
        }

        // Get the creation time of a well-known directory.
        DateTime dt = File.GetLastWriteTime(path);
        Console.WriteLine("The last write time for this file was {0}.", dt);

        // Update the last write time.
        File.SetLastWriteTime(path, DateTime.Now);
        dt = File.GetLastWriteTime(path);
        Console.WriteLine("The last write time for this file was {0}.", dt);  
  • What is the output? Do you get an exception, and if so can you post that? – Josh Mar 09 '16 at 17:12
  • 1
    no this code does not work on server its for local base files –  Mar 09 '16 at 17:15
  • I don't understand what you mean by "does not work on server." If the path and permissions are correct then this should work fine. You'll need to post the exception you're getting or clarify the question in order to get help troubleshooting. – Josh Mar 09 '16 at 17:19
  • i just edit the question. take look i take the argument not valid exception. i want to search all the directories on my web Host and search for new files and if there was a new file i will download that file. –  Mar 09 '16 at 17:31

1 Answers1

1

First I see you have an http:// on your path, do you want to get the metadata of remote files?

You need to run this code on the server side, and then expose that data by GET API / web service

To get the creation time of a file / directory.

System.IO.File.GetCreationTime('path_to_the_file');

path_to_the_file must be local.

JOBG
  • 4,544
  • 4
  • 26
  • 47
  • I just need the creation file to check if its new or not. you mean I cant do it with remoting to the server?? i have to run the application on the server? –  Mar 09 '16 at 17:53
  • 1
    Are you running your code directly on the server? If not you cannot use any `File` class methods, that´s just for local files. – JOBG Mar 09 '16 at 17:56
  • no i run my code on my local computer. how can i get the creation date like that? shall i use ftp request to my server or some thing?? –  Mar 09 '16 at 18:00
  • Check this: http://stackoverflow.com/questions/4454281/retrieving-creation-date-of-file-ftp – JOBG Mar 09 '16 at 18:38