Firstable, я нахожусь в WebForms ASP.NET.
В методе, который я написал,
string source = Global.PathTempFile + fileNamePosted + ".htm";
using (FileStream fs = new FileStream(source, FileMode.Create))
{
using(StreamWriter w = new StreamWriter(fs, Encoding.UTF8))
{
w.WriteLine(Request.Form["hide_redige"]);
}
}
bool exist = File.Exists(source); // true here (for test)
new MoveFile(source, Global.HADmdcdc + "\\" + fileNamePosted + ".htm", true);
Этот код создает новый файл в моей временной папке, на данный момент,File.Exists ()
распознает файл, но по соображениям безопасности я создал класс для управления файлом как конкретным пользователем (у которого есть права на запись в целевую папку)
public MoveFile(string sourcePath, string targetPath, bool isImpersonate)
{
if (isImpersonate)
moveImp(sourcePath, targetPath);
else
move(sourcePath, targetPath);
}
private void moveImp(string sourcePath, string targetPath)
{
if (imp.impersonateValidUser(id["domain"], id["login"], id["password"]))
move(sourcePath, targetPath);
imp.undoImpersonation();
}
private void move(string sourcePath, string targetPath)
{
if (File.Exists(sourcePath)) // false here
{
if (File.Exists(targetPath))
File.Delete(targetPath);
File.Move(sourcePath, targetPath);
}
}
Итак, мой вопрос: почему тест File.Exists () возвращает другое значение?Кроме того, я уверен, что файл существует.