Problem to copy file

HuaMin Chen
HuaMin Chen used Ask the Experts™
on
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

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Ryan ChongSoftware Team Lead

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?
HuaMin ChenProblem 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.
Ryan ChongSoftware Team Lead

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?
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

HuaMin ChenProblem 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?
Ryan ChongSoftware Team Lead

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?
HuaMin ChenProblem 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).
Ryan ChongSoftware Team Lead

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

Author

Commented:
Yes.
Ryan ChongSoftware Team Lead

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?
HuaMin ChenProblem 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?
Ryan ChongSoftware Team Lead

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
HuaMin ChenProblem 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?
Ryan ChongSoftware Team Lead

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.
Software Team Lead
Commented:
try something like this to see if you got any error

try
            {
                String str0 = "C:/inetpub/VS2012/Own_rec4/output63627510439367.jpg";
                if (!File.Exists(str0))
                {
                    System.IO.File.Copy("C:/inetpub/VS2012/Own_rec4/empty.jpg", str0, true);
                    Label1.Text = "Done! File copied";
                }
                else
                {
                    Label1.Text = "File already exist!";
                }
            }
            catch (Exception ex)
            {
                Label1.Text = ex.Source + ": " + ex.Message + ":" + ex.StackTrace;
            }

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial