locked
How can i not allow deletion of a file in c# RRS feed

  • Question

  • User1253338400 posted

    I have a file on my c drive that i read its contents using a simple console app. 

    If the file doesnt exist I create it . 

    How can i not allow the user to delete the file from windows , but only through an event I can put on a button in my c# app ?>

    Monday, April 6, 2020 8:48 AM

Answers

  • User475983607 posted

    But i dont want a user in windows to be able to delete the file by right click ---> delete or hit the delete key and delete the file.

    If i write to the file i want to be able to take off permissions write the new data to the file and re-add the non-delete permissions?

    For the second time!  Create a local user account (it could also be a domain account) and give the account read/write access to the temp directory.  All other accounts get read only except maybe an admin.  You application simple has to run under the new account.

    If this is a web application then give the application pool identity read/write.  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 6, 2020 11:59 PM

All replies

  • User475983607 posted

    robby32

    I have a file on my c drive that i read its contents using a simple console app. 

    If the file doesnt exist I create it . 

    How can i not allow the user to delete the file from windows , but only through an event I can put on a button in my c# app ?>

    I'm not sure how this is an ASP.NET or C# question.  Create a user on the machine.  Then only allow the local user account to delete the file.  Right click a folder -> properties -> Security.  

    You can also password protect a file of folder.  Just Google...

    https://www.google.com/search?rlz=1C1CHBF_enUS838US838&sxsrf=ALeKk01jPpjpVBLgksIve_cvX6SwMnP13w:1586181078778&q=how+to+password+protect+a+folder+in+windows+10&sa=X&ved=2ahUKEwjVwP_9-NPoAhVNUt8KHaU2B0AQ1QIoAHoECAsQAQ&biw=1536&bih=722 

    Monday, April 6, 2020 1:56 PM
  • User1253338400 posted

    How can this be done programatically using c# ?

    Monday, April 6, 2020 9:06 PM
  • User475983607 posted

    How can this be done programatically using c# ?

    Programmatically do what?  Please be explicit.

    Monday, April 6, 2020 9:15 PM
  • User1253338400 posted

    I can currently creat a text file using c#. Lets say file.txt. which sits in the c:\temp directory.

    I can add some  text in the file.

    But i dont want a user in windows to be able to delete the file by right click ---> delete or hit the delete key and delete the file.

    If i write to the file i want to be able to take off permissions write the new data to the file and re-add the non-delete permissions?

    Monday, April 6, 2020 11:01 PM
  • User475983607 posted

    But i dont want a user in windows to be able to delete the file by right click ---> delete or hit the delete key and delete the file.

    If i write to the file i want to be able to take off permissions write the new data to the file and re-add the non-delete permissions?

    For the second time!  Create a local user account (it could also be a domain account) and give the account read/write access to the temp directory.  All other accounts get read only except maybe an admin.  You application simple has to run under the new account.

    If this is a web application then give the application pool identity read/write.  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 6, 2020 11:59 PM