File.Copy Method timing issues.

B

Brian Hanson

Hi,

I have a problem that is sporadic and am thinking it may come down to
a timing issue. I have an asp.net (vb) app that used the
system.io.file.copy method to copy a .pdf file from a network drive to
the local server drive. From there I use that .pdf file to create
another .pdf file using a tool from ActivePDF. The problem I have is
that one out of 8 or 10 times I get an error:

Access to the path "c:\ActivePDF\watever.pdf" is denied.

This is the file I just copied from the network and am trying to use
for something else.

If I try it again, it usually works right away. Since it usually
works, I can eliminate any permission issues, and wonder if it is a
timing issue.
I thought that the file.copy method was synchronous so it will finish
its copy before moving on to the next bit of code. I then looked at
the indexing features of the folder the file was being copied to and
made sure that indexing was turned off. I have not, however,
eliminated ActivePDF from being the problem child.

Thanks for any ideas.
 
S

Steven Cheng[MSFT]

Hi,


Thanks for posting in the community!
From your description, you used the System.IO.File.Copy method to copy a
file from a remote address and then use it in an ASP.NET web application.
However, you found that sometimes there occured Access Denied error at
runtime. Also, you suspect it was caused by time issue, yes?
If there is anything I misunderstood, please feel free to let me know.

Based on my experience, access resource on remote site will often caused
security issues. But since you've mentioned that the error is after file's
been copied to local and it works well usually. I also doubt whether it is
caused by
concurrency issue on the copied file. Would you please try the following
steps:
1. copying file from a local different folder rather than a network driver
to see whether the problem remains. then, we can confirm whether this is
likely caused by the time issue or not.

2. Also , you can try accessing(read) the file after it has been copied(in
a try... catch ...block) so as to determined whether it is concurrent
visited or completely copied.

Please check out the above things, if the situation is not quite suitable,
please feel free to let me know.



Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Steven Cheng[MSFT]

Hi,


Have you had a chance to try out the preceding suggestions I provided in
the last reply or have you got any progress on this issue? If you need any
further assistance, please feel free to post here.



Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
B

Brian Hanson

Hi,

Thanks for replying (twice). I made a couple of changes programatically
that may have solved my problem.

1) I removed a loop, that because of other reasons, I no longer needed.
2) I removed a random number generator I was using to come up with a
unique file name and added time stamp. I may be crazy, but It seems to
me that the random number generator in .net is not all that random.

I have run about 50 tests without getting the error. Still more testing
to go, because it was sporatic in the first place, but hopefully, that
did the trick.

Thanks

Brian
 
S

Steven Cheng[MSFT]

Hi Brian,


Thanks for your followup and the latest info you provided. I'm glad you've
got progress on this issue. In addition, if you meet problem in the
furture, please always feel free to post here. We are willing to help you.



Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
T

Tim Sullivan

Brian,
2) I removed a random number generator I was using to come up with a
unique file name and added time stamp. I may be crazy, but It seems to
me that the random number generator in .net is not all that random.

FYI - The GetUniqueFileName method of Toolkit will generate a truly
unique filename for you. That method also works for simultaneous
unique name creation across processes and threads.

Tim Sullivan
 
A

Amit Singla

hi Steven,

I also have the similar problem. i am not able to copy the image file
from the remote machine to the client machine dynamically at the
specified location at the run time through ASp.net using VB.net.Can you
please help me regarding this.


Looking forward to hearing from you soon.

Regards,
Amit Singla
Software Engineer
 
A

Amit Singla

hi Steven,

I also have the similar problem. i am not able to copy the image file
from the remote machine to the client machine dynamically at the
specified location at the run time through ASp.net using VB.net.Can you
please help me regarding this.


Looking forward to hearing from you soon.

Regards,
Amit Singla
Software Engineer
 
J

J33

Hi, I've The Same Problem.

I Can't Copy A Local File To Some Server With File.copy In Vb.net,,
For Example: (source, Destination) If Destination Is A Url Path, Th
File Haven´t Been Copied
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top