简体   繁体   中英

Access to path denied when i write and save the file on server

System.UnauthorizedAccessException: Access to the path 'C:\Inetpub\wwwroot\HealthCard\NewsTextFiles\News.html' 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)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)

I am using ckeditor . Edit the file on server and save the file on server. It is not working on server but it is well working on my localmachine.

Here is code of edit and save button.

protected void btnSaveNews_Click(object sender, EventArgs e)
    {

        string str = Ckeditor.Text;

        string str1 = Server.HtmlDecode(str);

        //lblText.Text = str2;


        FileStream fs = new FileStream(Server.MapPath("~/NewsTextFiles/News.html"), FileMode.Create , FileAccess.Write);
        StreamWriter wr = new StreamWriter(fs);
        wr.Write(str1);


        wr.Dispose();
        fs.Dispose();

        pnleditor.Visible = false;
        upleditor.Update();
        upleditor.Visible = false;

    }

Make sure the user your Application Pool is running as has write permissions on that file / folder.

This might be:

IIS_USR or Network Service (can also be others).

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