简体   繁体   English

在C#中获取服务器文件的创建时间

[英]get creation time of a server file in c#

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);  

First I see you have an http:// on your path, do you want to get the metadata of remote files? 首先,我看到您的路径上有一个http:// ,是否要获取远程文件的元数据?

You need to run this code on the server side, and then expose that data by GET API / web service 您需要在服务器端运行此代码,然后通过GET API / Web服务公开该数据

To get the creation time of a file / directory. 获取文件/目录的创建时间。

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

path_to_the_file must be local. path_to_the_file必须是本地的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM