【发布时间】:2016-03-09 16:57:55
【问题描述】:
您好,我想创建一个连接到我的主机的应用程序,并检查目录中是否添加了任何新文件。 所以我需要该主机文件的创建时间,但我无法连接到服务器。 我只是找到了一些用于服务器文件创建时间的代码,但我不知道为什么它们不能以某种方式工作。 有什么建议吗?
这是代码:
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);
【问题讨论】:
-
输出是什么?你有例外吗,如果有,你可以发布吗?
-
不,此代码不适用于本地基础文件的服务器
-
我不明白您所说的“在服务器上不起作用”是什么意思。如果路径和权限正确,那么这应该可以正常工作。您需要发布您遇到的异常或澄清问题,以获得帮助进行故障排除。
-
我只是编辑问题。看看我认为参数无效异常。我想搜索我的网络主机上的所有目录并搜索新文件,如果有新文件,我将下载该文件。