none
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,

    Timon


    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 MSDNFSF@microsoft.com.

    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

    or

    - 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

    https://www.tutorialspoint.com/asp.net_wp/asp.net_wp_working_with_files.htm

    @{
       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>
    <html>
       
       <head>
          <title>Write Data to a File</title>
       </head>
       
       <body>
          <form id = "form1" method = "post">
             <div>
                
                <table>
                   <tr>
                      <td>First Name:</td>
                      <td><input id = "FirstName" name = "FirstName" type = "text" /></td>
                   </tr>
                   
                   <tr>
                      <td>Last Name:</td>
                      <td><input id = "LastName" name = "LastName" type = "text" /></td>
                   </tr>
                   
                   <tr>
                      <td>Marks:</td>
                      <td><input id = "Marks" name = "Marks" type = "text" /></td>
                   </tr>
                   
                   <tr>
                      <td></td>
                      <td><input type = "submit" value = "Submit"/></td>
                   </tr>
                </table>
             </div>
             
             <div>
                @if(result != ""){
                   <p>Result: @result</p>
                }
             </div>
          
          </form>
          
       </body>
    </html>


    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.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Friday, January 17, 2020 11:08 AM
    Moderator