Solved

2 buttons, add and remove to append to and delete from file in aspx page.

Posted on 2014-01-25
1
301 Views
Last Modified: 2014-02-11
Hi;

I have 2 buttons, add and remove to append to and delete line (value in textbox) from file in aspx page respectively.

The thing is that I got in the point that the contents of the file must be loaded if it's not postback (first load) to a dropdown.

Is there a sample feasible algorithm for this? or a pseudocode? or the code? (I have to check file's existency or whether it's empty or not to be free of exceptions)

Kind regards.
0
Comment
Question by:jazzIIIlove
1 Comment
 
LVL 16

Accepted Solution

by:
Easwaran Paramasivam earned 500 total points
ID: 39809745
You can use Page.IsPostback property is true or not. If not true then check whether file exists or not using File.Exists(filename). If exists then read the  file content File.ReadToEnd() , it will return string. If the string is not empty then use in your application. Psuedocode goes like given below.


if(!Page.IsPostback)
{

   if(File.Exists("yourfilegoeshere")
  {

    string content = File.ReadToEnd("yourfilegoeshere")
    if(content.Trim() != string.Empty)
    //has content use it. 

  }
}

Open in new window

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question