Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
343 views
in Technique[技术] by (71.8m points)

c# - Access denied when using File.Copy

after few days of searching and investigating the problem, I finnaly decided to ask the question over here. In the beginning I want to apologize for my english, it's not so well as it should be, so hope, you'll understand the question well :).

I have a problem when using File.Copy in ASP.NET to summarize the problem - it always says, that I don't have the permission to access the folder defined in "pathFrom". (the only way how the code works is, when I run it in my Visual Studio in debugger), after I upload it on web server, it stops working.

CODE:

protected void buttonclick(object sender, Eventargs e){
string pathFrom = "\\sqlSRV\folder1\thisOne.txt";
string pathTo = "\\webSRV\folder2\overHere.txt";

string directory = "\\sqlSRV\folder2";
if (Directory.Exists(directory))
{
    try
    {
        File.Copy(pathFrom, pathTo, true);
    }
    catch (FileNotFoundException)
    {
        Lab0.Text = "Not found.";
    }
    catch (FileLoadException)
    {
        Lab0.Text = "Cant open.";
    }
}
  • The servers are in the same domain.
  • Shared folders does have ALL permissions for sqlSRV$ and webSRV$, NETWORK SERVICE, IIS_WPG even for group Everyone (just for testing right now)
  • we don't want to use impersonate and write the username and password into the code due to security
  • everything is on our LAN
  • running IIS10

In the old days we had similiar function in ActiveX, where it all worked (because it knew which user was running the code).

Can anyone, please, help?

Thanks a lot

question from:https://stackoverflow.com/questions/65951942/access-denied-when-using-file-copy

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...