avatar
File.Copy怎么老是出错?# DotNet - 窗口里的风景
c*t
1
File.Copy("C:\Temp\tmp.pdf", "S:\Somedir\MM-dd-yyyy.pdf");
Where S: is a mapped network drive. Sometime it works, sometime the copy
failed, pdf file corrupted. Tried to catch, no error found.
Any suggestion?
avatar
c*t
2
Found possible reason. Once File.Copy is execute, my prog sends out email
notice
Maybe the copy isn't done; somebody has already clicked on the link to see
the target file, which will lock/abort the copy..
Just one guess, any other clue? I tried to wait for a few more seconds
till
the copy is done, let me see if it could prevent the issue..

【在 c**t 的大作中提到】
: File.Copy("C:\Temp\tmp.pdf", "S:\Somedir\MM-dd-yyyy.pdf");
: Where S: is a mapped network drive. Sometime it works, sometime the copy
: failed, pdf file corrupted. Tried to catch, no error found.
: Any suggestion?

avatar
a9
3
why not send notice after copy?

【在 c**t 的大作中提到】
: Found possible reason. Once File.Copy is execute, my prog sends out email
: notice
: Maybe the copy isn't done; somebody has already clicked on the link to see
: the target file, which will lock/abort the copy..
: Just one guess, any other clue? I tried to wait for a few more seconds
: till
: the copy is done, let me see if it could prevent the issue..

avatar
c*t
4
the email was sent out after the copy command; in which it checks
File.Exists(CopiedFileName), but still the PDF corrupted.

【在 a9 的大作中提到】
: why not send notice after copy?
avatar
D*y
5
the file might already be there before the copy is finished...

【在 c**t 的大作中提到】
: the email was sent out after the copy command; in which it checks
: File.Exists(CopiedFileName), but still the PDF corrupted.

avatar
c*t
6
Before copy the file, I have done:
if ( File.Exists(RemoteFile) )
{
File.Delete(RemoteFile);
}
File.Copy(ToBeCopiedFile, RemoteFile);
Notifiy(); //send email out

【在 D******y 的大作中提到】
: the file might already be there before the copy is finished...
avatar
a9
7
File.Copy是同步操作,不是你想的那个原因。

【在 c**t 的大作中提到】
: Before copy the file, I have done:
: if ( File.Exists(RemoteFile) )
: {
: File.Delete(RemoteFile);
: }
: File.Copy(ToBeCopiedFile, RemoteFile);
: Notifiy(); //send email out

avatar
a9
8
对了,你这是winform,还是服务还是asp.net?

【在 c**t 的大作中提到】
: Before copy the file, I have done:
: if ( File.Exists(RemoteFile) )
: {
: File.Delete(RemoteFile);
: }
: File.Copy(ToBeCopiedFile, RemoteFile);
: Notifiy(); //send email out

avatar
c*t
9
console app

【在 a9 的大作中提到】
: 对了,你这是winform,还是服务还是asp.net?
avatar
a9
10
你这两个问题是一个问题吗?
到底程序是怎么个运行法?
我试了一下,完全没问题。

【在 c**t 的大作中提到】
: console app
avatar
c*t
11
不同的问题。我的程序用了3rd party的软件,print url to pdf, 这个需要在guest
account 的 context 中加 printer,并且对某个folder有读写权限。
如果直接 process.StartInfo.FileName=3rdPathApp, process.StartInfo.Arguments=
url
没有pdf生成。即使源程序在local admin account下运行,因为要调用browser,其
权限自动的用guest替代。
编辑一个bat: 3rdPartyApp url, process.StartInfo.FileName=thisBatch,就可以
工作了。因为执行batch,用的是local admin account的profile,就可以了。
问题最终是解决了。

【在 a9 的大作中提到】
: 你这两个问题是一个问题吗?
: 到底程序是怎么个运行法?
: 我试了一下,完全没问题。

avatar
a9
12
不懂。为啥调用browser就成了guest了。

Arguments=

【在 c**t 的大作中提到】
: 不同的问题。我的程序用了3rd party的软件,print url to pdf, 这个需要在guest
: account 的 context 中加 printer,并且对某个folder有读写权限。
: 如果直接 process.StartInfo.FileName=3rdPathApp, process.StartInfo.Arguments=
: url
: 没有pdf生成。即使源程序在local admin account下运行,因为要调用browser,其
: 权限自动的用guest替代。
: 编辑一个bat: 3rdPartyApp url, process.StartInfo.FileName=thisBatch,就可以
: 工作了。因为执行batch,用的是local admin account的profile,就可以了。
: 问题最终是解决了。

avatar
k*i
13
This may help you
http://odetocode.com/Blogs/scott/archive/2004/10/28/602.aspx

Arguments=

【在 c**t 的大作中提到】
: 不同的问题。我的程序用了3rd party的软件,print url to pdf, 这个需要在guest
: account 的 context 中加 printer,并且对某个folder有读写权限。
: 如果直接 process.StartInfo.FileName=3rdPathApp, process.StartInfo.Arguments=
: url
: 没有pdf生成。即使源程序在local admin account下运行,因为要调用browser,其
: 权限自动的用guest替代。
: 编辑一个bat: 3rdPartyApp url, process.StartInfo.FileName=thisBatch,就可以
: 工作了。因为执行batch,用的是local admin account的profile,就可以了。
: 问题最终是解决了。

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。