File password with C# RRS feed

  • Question

  • I want to write a functionality in asp .net with c# which can append a password to a file.

    Regrds, Jitendra

    Friday, January 17, 2020 7:14 AM

All replies

  • Hi kjitendra,

    Thank you for posting here.

    I have a question want to confirm.

    What type of file are you using?

    If it is a text file, we can use the following code to append a string to the file, if not, we may need to use a special API, depending on the type of file you use.

            static void Main(string[] args)
                DoWork("Hello World");
            public static void DoWork(string str) 
                File.AppendAllText(@"D:\test\txt\pass.txt", str+Environment.NewLine);

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Friday, January 17, 2020 9:42 AM
  • Hello,

    >I want to write a functionality in asp .net with c# which can append a password to a file.

    And what stop you to do so? 

    By the way - I do not understand what exactly you want to do:

    - write password as text to the file


    - manage access right for the file? 

    Sincerely, Highly skilled coding monkey.

    Friday, January 17, 2020 9:51 AM
  • Hello,

    See the following example under the section Append Data to an Existing File

       var result = "";
       if (IsPost){
          var firstName = Request["FirstName"];
          var lastName = Request["LastName"];
          var marks = Request["Marks"];
          var userData = firstName + "," + lastName + "," + marks + Environment.NewLine;
          var dataFile = Server.MapPath("~/App_Data/Data.txt");
          File.AppendAllText(@dataFile, userData);
          result = "Information saved.";
    <!DOCTYPE html>
          <title>Write Data to a File</title>
          <form id = "form1" method = "post">
                      <td>First Name:</td>
                      <td><input id = "FirstName" name = "FirstName" type = "text" /></td>
                      <td>Last Name:</td>
                      <td><input id = "LastName" name = "LastName" type = "text" /></td>
                      <td><input id = "Marks" name = "Marks" type = "text" /></td>
                      <td><input type = "submit" value = "Submit"/></td>
                @if(result != ""){
                   <p>Result: @result</p>

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    profile for Karen Payne on Stack Exchange

    Friday, January 17, 2020 11:08 AM