简体   繁体   中英

c# File.Copy from \\127.0.0.1

In C# (.NET 2.0), I have the following line of code:

File.Copy(fileName, @"C:\Temp\someDir\SomeFile.jpg"); 

where fileName is "\\\\127.0.0.1\\someDir\\someFile.jpg". I get an IOException that says "The system detected a possible attempt to compromise security. Please ensure that you can contact the server that authenticated you."

Any idea what is going on here?

Thanks, Scott

The File class accepts path that can be UNC path for server or share. So in your case File.Copy is assuming that the fileName is a UNC path of a server or share hence the copy method throws exception

File.Copy("\\127.0.0.1\someDir\someFile.jpg", @"C:\Temp\someDir\SomeFile.jpg");

I would suggest you try to use WebClient.UploadFile

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM