简体   繁体   English

如何使用delphi xe3复制像.pst这样的锁定文件

[英]How to copy a locked file like .pst using delphi xe3

I am struggling to find an answer to the following problem.我正在努力寻找以下问题的答案。 Any and all help would be appreciated.任何和所有帮助将不胜感激。

I am using the following code to try and copy an outlook.pst file while outlook is open.我正在使用以下代码在 Outlook 打开时尝试复制 Outlook.pst 文件。 And i cannot get it to succeed.我无法让它成功。 It does not give an error, it just doesnt copy the file.它没有给出错误,它只是不复制文件。

copyfile('C:\Users\Administrator\Documents\Outlook Files\Outlook.pst','F:\Outlook.pst');

If you guys know how i will be able to copy a locked file like that please assist.如果你们知道我将如何复制这样的锁定文件,请提供帮助。

I have tried and found that TFilestream also does not work.我试过发现 TFilestream 也不起作用。

And those 2 are the only options i know off.这两个是我所知道的唯一选择。 any help would be greatly appreciated.任何帮助将不胜感激。

Thank You谢谢你

I have tried the following code as-well and get an error saying that the file is in use from another process(outlook).我也尝试了以下代码并收到一条错误消息,指出该文件正在从另一个进程(outlook)中使用。

procedure TForm1.Button2Click(Sender: TObject);
var
   NewFileName: string;
   NewFile: TFileStream;
   OldFile: TFileStream;
Begin
           NewFileName:='F:\outlook.pst';
           OldFile := TFileStream.Create('C:\Users\Administrator\Documents\Outlook Files\outlook.pst', fmOpenRead or fmShareDenyWrite);
            try
              NewFile := TFileStream.Create(NewFileName, fmCreate or fmShareDenyNone);
              try
                NewFile.CopyFrom(OldFile, OldFile.Size);
              finally
                FreeAndNil(NewFile);
              end;
            finally
              FreeAndNil(OldFile);
            end;
end;

Please see the following link.请参阅以下链接。 If anybody can convert the code.如果有人可以转换代码。 the problem should be solved.问题应该得到解决。 How to copy a pst file while it is open using c# 如何在使用 c# 打开时复制 pst 文件

PST provider locks PST files until the parent process terminates. PST 提供程序锁定 PST 文件,直到父进程终止。 Even if you close the PST file from Outlook, it will be kept open for 30 minutes for the performance reasons.即使您从 Outlook 关闭 PST 文件,出于性能原因,它也会保持打开状态 30 分钟。

Do you programmatically open the PST file in Outlook?您是否以编程方式在 Outlook 中打开 PST 文件?

Try the fmShareDenyNone flag when creating the TFileStream object:创建 TFileStream 对象时尝试 fmShareDenyNone 标志:

stream := TFileStream.Create(filename, fmOpenRead or fmShareDenyNone);
try 
   slFile.LoadFromStream(stream);
finally
   stream.Free;
end;

Function to read the date from a file:从文件中读取日期的函数:

function GetFileDate(TheFileName: string): string;
var
  FHandle: integer;
begin
  FHandle := FileOpen(TheFileName, fmShareDenyNone);
  try
    Result := DateTimeToStr(FileDateToDateTime(FileGetDate(FHandle)));
  finally
    FileClose(FHandle);
  end;
end;

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

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