Link to home
Start Free TrialLog in
Avatar of Peter Chan
Peter ChanFlag for Hong Kong

asked on

Problem to copy file

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?
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

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?
Avatar of Peter Chan

ASKER

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.

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?
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?
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?
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).
is that your current issue - you're not able to copy the file and hence not able to show in web browser?
Yes.
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?
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?
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
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?
I can copied the file locally in my ASP.NET application.

User generated image
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.
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial