We help IT Professionals succeed at work.

Problem to copy file

335 Views
Last Modified: 2017-04-10
Hi,
Here is error I can see
https://app.box.com/s/hdp8hqqcknt3ls98jnrrlnc21bug9c20

on Chrome browser, while I have such codes

            if (!File.Exists(str0))
            {
                System.IO.File.Copy("C:/inetpub/VS2012/Own_rec4/empty.jpg", str0, true);
            }

Open in new window


and str0 is having value like

C:/inetpub/VS2012/Own_rec4/output63626911810308.jpg

What is the reason of the error?
Comment
Watch Question

CERTIFIED EXPERT

Commented:
make sure the path of the file you want to copy is valid and accessible via coding?

the error in your picture doesn't mean the file cannot be copied via server side (System.IO.File.Copy), it's more likely that your file cannot be found from server end.

are you doing a wrong file mapping?
Peter ChanProblem resolver

Author

Commented:
Yes, I did put such line
System.IO.File.Copy("C:/inetpub/VS2012/Own_rec4/empty.jpg", str0, true);

Open in new window


and do not know why the file cannot be copied as expected.
CERTIFIED EXPERT

Commented:

and do not know why the file cannot be copied as expected.
so start debug by checking 2 things:

1. is that file exists?
2. is that path mapped correctly to your web server?
Peter ChanProblem resolver

Author

Commented:
I check that it does run the 2 lines of this condition
if (!File.Exists(str0))
            {
                System.IO.File.Copy("C:/inetpub/VS2012/Own_rec4/empty.jpg", str0, true);
                lb_msg.Text = str0;
            }
           

Open in new window


but the file (by str0) is not created. And the path is correct. str0 is having value lie

C:/inetpub/VS2012/Own_rec4/output63627092287920.jpg 

Open in new window


What can be the reason?
CERTIFIED EXPERT

Commented:
but the file (by str0) is not created
is there any error you can detected from your codes?

so i guess you got write permission issue to your targeted file path? try check and make sure you got the write permission to that targeted folder?
Peter ChanProblem resolver

Author

Commented:
Hi,
As this is running against folder (on Web server) and I see that
IIS_IUSRS

is having full control to the folder (C:/inetpub/VS2012/Own_rec4).
CERTIFIED EXPERT

Commented:
is that your current issue - you're not able to copy the file and hence not able to show in web browser?
Peter ChanProblem resolver

Author

Commented:
Yes.
CERTIFIED EXPERT

Commented:
is having full control to the folder (C:/inetpub/VS2012/Own_rec4).
if you got full permission, you should able to write to the target folder.

can you do a test to copy other file and file types to that folder? will that work for you?
Peter ChanProblem resolver

Author

Commented:
Yes, I can copy the file if I login the server but this is totally different, right? The access on the web-page is using another account having different permissions, correct?
CERTIFIED EXPERT

Commented:
The access on the web-page is using another account having different permissions, correct?
exactly, so it seems that you can't write to that targeted folder via your IIS. you got check and make sure you got appropriate permission on that.

you may also check these out and see if you can fix the write permission issue.

How to configure Web server permissions for Web content in IIS
https://support.microsoft.com/en-us/help/313075/how-to-configure-web-server-permissions-for-web-content-in-iis

Setting Write Permissions on the File Upload Folder
http://www.banmanpro.com/support2/permissions.asp

Setting Up Folder Permissions in Internet Information Services (IIS)
https://www.kbpublisher.com/kb/setting-up-folder-permissions-in-internet-information-services-(iis)_392.html
Peter ChanProblem resolver

Author

Commented:
It does get into this part but the System line does not create the file as expected
            if (!File.Exists(str0))
            {
                System.IO.File.Copy("C:/inetpub/VS2012/Own_rec4/empty.jpg", str0, true);
            }

Open in new window


while str0 is having value

C:/inetpub/VS2012/Own_rec4/output63627510439367.jpg

Open in new window


Why?
CERTIFIED EXPERT

Commented:
I can copied the file locally in my ASP.NET application.

SnapShot.png
please make sure you got write permission to that folder.

check the resources posted in comment; ID: 42085873 for more info.

try do similar tests for different file names, file sizes, file types and different folders.
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.