Home cant access a file using C# asp mvc application
Reply: 0

cant access a file using C# asp mvc application

user8775
1#
user8775 Published in September 19, 2018, 9:09 am

I have an mvc asp application that needs to edit a file by the name of test.php I didnt have any error using this method in my LocalHost , when i transfered it to server i get this error :

System.UnauthorizedAccessException: Access to the path 'C:\Users\Administrator\Desktop\codeEditor\test.php' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean checkHost) at System.IO.File.InternalReadAllText(String path, Encoding encoding, Boolean checkHost) at System.IO.File.ReadAllText(String path) at ASP._Page_Areas_user_Views_php_dark_cshtml.Execute() in C:\Inetpub\vhosts\tutpersia.com\httpdocs\Areas\user\Views\php\dark.cshtml

I tried changing permissions of my directory using Plesk or by right click and ... but still the same error

what Im trying to do in my app is :

  string filePath = "C:\\Inetpub\\vhosts\\sth.com\\httpdocs\\test.php";

            string text = System.IO.File.ReadAllText(filePath);
            System.IO.File.WriteAllText(filePath, text+"sth");

thank you all

share|improve this question
  • What you mean by "transfered it to server"? – SeM Apr 17 at 5:47
  • 1
    Your error message and posted code don't add up. – nvoigt Apr 17 at 10:40
  • Your error message says you tried to access a file on the desktop, not the web site's folder – Panagiotis Kanavos Apr 17 at 10:41

1 Answer 1

active oldest votes
up vote 0 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.309049 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO