Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 316
  • Last Modified:

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

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
jazzIIIlove
Asked:
jazzIIIlove
1 Solution
 
Easwaran ParamasivamCommented:
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now