Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The requested operation cannot be performed on a file with a user-mapped section open
Error on this line
System.IO.File.Copy(tempPath, filePath, True)

What I have tried:

If pdfStamper IsNot Nothing Then pdfStamper.Close()
If pdfReader IsNot Nothing Then pdfReader.Close()
System.IO.File.Copy(tempPath, filePath, True)
System.IO.File.Delete(tempPath)
End if
Posted
Updated 7-Jan-20 1:02am

1 solution

The error message is pretty explicit:
The requested operation cannot be performed on a file with a user-mapped section open
The file is open, probably elsewhere in your own app - and cannot be opened by the external process to copy the file until it is closed.

Check all your other code and make sure you do not maintain any access to the file. That includes any Image controls you have loaded from the file, and so on.
As a good practice, use a Using block around any streams etc. throughout your code to ensure that the file is correctly closed and relevant structures disposed when you are finished with them.
 
Share this answer
 
Comments
Computechsoft 7-Jan-20 7:06am    
If i am restarting my system when again start my project first time run perfectly
second time coming this error.
phil.o 7-Jan-20 7:22am    
It means that there is a flaw in your code which leaves a file stream open when it should dispose of it. Make sure you declare all streams with using blocks, as suggested in the solution, and you will be fine.
Computechsoft 7-Jan-20 8:44am    
PdfReader was installed in my system? now this document opening in "Microsoft Edge"
therefore this error showing now tell me i am applying this
Kill("Microsoft Edge.lnk")
but not be killing (Microsft Edges)
OriginalGriff 7-Jan-20 9:06am    
You'd have to kill the process - not the link. But ... That wouldn't work on my system, because mine opens PDF files with Corel PDF Fusion. And even if I did use Edge to open PDF files, you go closing my browser at whim and I'm going to uninstall your software with extreme prejudice!

Instead of trying to "work round" the problem, use Try...Catch to "pick up" the error, report it to your user and give him a chance to close the viewer manually and retry.
Computechsoft 7-Jan-20 9:15am    
Yes i have closed manually "Microsoft Edge" no error perfect working.
Only i have to close "Microsoft Edge" Pragmatically ?
but Edges Lenth = 0

Dim Edges() As Process = Process.GetProcessesByName("Microsoft Edge")

For Each Process As Process In Edges
Process.Kill()
Next

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900