Powered by Blogger.

Thursday, September 26, 2013

Read and write from Text file in Asp.Net



Here we will disucss how we can read and write from a text file in Asp.net.

You will get a string array while reading all the lines and it will store one line to an array element in C#.Net.

And once you will get the array then you can modify what ever you want and then you can Write the whole array to the file.

Here is the code:

string[] Details = new string[0];
string strPath = @"C:\myfile.txt";
if (File.Exists(strPath))
            {
                Details = File.ReadAllLines(strPath);
            }

//Here you will get in the form of array
            Details [0] = "password^###~" + "What ever text you want";
Here you can write the whole array to the file.
            File.WriteAllLines(strPath, Details );





0 comments

Post a Comment