检查文件是否完整 [英] Check if file is complete

查看:41
本文介绍了检查文件是否完整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨大家好,

我是从水晶报表创建PDF,然后直接用adobe reader打开它。 

Im creating a PDF from crystal reports and then open it with adobe reader straight after. 

但是,有时我认为adobe reader会在完全创建文件之前尝试打开它。 (pdf文件存在但仍未完成)

However, sometimes I think adobe reader tries to open the file before it is fully created. (The pdf file exists but is still not complete)

这是我的代码:

// Get Date time for filename
String dt = DateTime.Now.ToString("yyyy-MM-dd-h-mm-ss");
fName = Utilities.Paths.pathToPDFs + fileNamePreFix + dt + ".pdf";
rep.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Utilities.Paths.pathToPDFs + fileNamePreFix + dt + ".pdf");


// Adding "\"" + path+filename + "\"" solves the problem of paths and filenames with spaces in them

Open("\"" + Utilities.Paths.pathToPDFs, fileNamePreFix + dt + ".pdf" + "\"", Utilities.Paths.pathToAdobeReader);
System.Diagnostics.Process.Start(Utilities.Paths.pathToAdobeReader, "\"" + Utilities.Paths.pathToPDFs + fileNamePreFix + dt + ".pdf" + "\"");
              

有没有办法可以检查以确保文件已完成?我考虑过在循环中检查文件大小。一旦文件大小在前一次迭代中相同,那么它必须完整。会有用吗?

Is there a way I can check to make sure the that the file is finished ? I thought about checking the file size within a loop. Once the file size is the same in previous iteration, then it must be complete. Would that work ?

jppnn

推荐答案

CrystalReports是第三方产品,因此与其相关的问题应该发布在他们的论坛中( http://www.sap.com/solution/sme/software/analytics/crystal-visual-studio/index.html)

关于您的问题,您应该查看该呼叫是阻止呼叫还是非阻止呼叫。如果是阻塞调用,则该文件应在方法返回之前完成,您不需要执行任何其他操作。 我相信框架附带的原始版本
是。但是SAP现在提供的版本可能不是。在这种情况下,他们应提供有关如何知道流程何时完成的文档。 监视文件大小更改是不可靠的,因为它们可能会在冗长的查询运行时冻结导出
。他们应该能够在论坛中更好地帮助你。

In regards to your question you should look to see if the call is a blocking or non-blocking call. If it is a blocking call then the file should be finished before the method returns and you don't need to do anything else.  I believe the original version that shipped with the framework was. But the version available now from SAP may not be. In that case they should provide documentation on how to know when the process is complete.  Monitoring for file size changes is unreliable since they may freeze export while a lengthy query runs. They should be able to assist you better over in their forums.

Michael Taylor

http://blogs.msmvps.com/p3net

Michael Taylor
http://blogs.msmvps.com/p3net


这篇关于检查文件是否完整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆