
#Append text to text file without new linein asp.net code
You can Download Source code for your reference for free.:not() selector in jquery (1). On pressing submit button we will successfully create a the Text file and write text in it. And also checking if the user as entered the name of the file and its content to write, if not we are showing Message on our ASP.NET label control. We are calling the WriteToFile method on our button click event and passing the txtFileName.Text as our File name and txtFileContent.Text as our File content to write on to the File. Public void WriteToFile(string fileName, string fileContent) LblInfo.Text = "Please enter File name and its content" If (String.IsNullOrWhiteSpace(()) || String.IsNullOrWhiteSpace(())) Protected void btnSubmit_Click(object sender, EventArgs e) Protected void Page_Load(object sender, EventArgs e) A ASP.NET button to submit our data and a Label to show the result. This design contains to ASP.NET textboxes, one to enter the file name and other to enter the text which we will write on to the file. Now we will create a complete design so that we can create new files. stream.WriteLine(fileContent) will write the text on a new line in our Text file. If the file exists, it will append the Text content in it. Also the Directory and File will be created if it doesn’t exist already.

Our folder path is "D:\FileWriter\", here the file will be created.

One for file name and other for the file contents. This method accepts two String parameters. LblInfo.Text = "Error occurred:"+ex.Message.ToString() StreamWriter stream = new StreamWriter(FolderPath + fileName, true) String FolderPath = (!Directory.Exists(FolderPath))įile.Create(FolderPath + fileName).Close() Using this method you will be able to create a Text file and write the contents on it: public void WriteToFile(string fileName, string fileContent)
