Have text file; need to search and extract to website - button

I have programming knowledge in Java, C++, C, C# and basic HTML. I just need some general direction of where to start with this task.
Do I need a database, like how would one go about doing this?
Books, subjects, keywords to look up, any help would be appreciated.
Basically I want user to click a button on website and have text from file go onto the site.
How hard is this task?

The simplest prototype of this I can think of is to use an HTML form and a PHP backend. On button click, submit the form and have the PHP process it on the backend. That can happen at http://yoursite.com/foo.php.
The backend then reads the content, sanitizes it, saves it to flat file or a database, and then sends out an "ok" type web page to the user.
Then, in another location on your site, say http://yoursite.com/bar.php, you simply read from that flat file or database, to display what the user put in.
Sure they could be the same page but then the code is more complex.
Simplistic, and not without security considerations, but hopefully it's enough to get you started down the right path.
I would not use C/C++ for this task, and Java or C# would be okay, but involve more effort than what I mention above.

C#, ASP.NET
create an asp.net web page
put button on it
put label and give it ID lblText
On button click read file like this:
var file = "full_path_to_a_file"; //like "C:\\textfile.txt"
var text = File.ReadAllText(file);
then attach text to your label
lblText.Text = text;
or whatever you want to do

Related

Scraping in R, aspx form don't know how to get data

Hello Im traying to scrape data from https://eservicios2.aguascalientes.gob.mx/sop/geobras/UI/frmObrasTodas.aspx
I can get the data from the main page but I don't know how to get the data from the form,
a) when choose a row and ask for "Detalle" , means detail goes to a form.
b) don't know how to follow the link
Need to get data from each row, can anybody help me.
the main issue and problem is that this is a asp.net web site. So, when you select a row, this likely uses a server side event. you MIGHT be able to write some JavaScript to select a row. But then the next issue is even more of a challenge. Once you select a row, then you have to click on a button. That button is going to run server side code. And that server side code is going to look at and grab the row value selected - VERY likely again server side code. Unlike say a simple web site with hyper-links?
.net sides are full driven from vb.net or c# code. We don't use silly things like hyper-links, or even silly parameters in the web URL.
So, after you select a row (perhaps possible in js), then you would then have to click on the details button. This again can be done with JavaScript
Say, in jQuery like this:
$('#NameOfButton').click();
So asp.net sites don't use simple code like what you see and get from someone who take that 3 day web developer program promising that now you are a experienced web developer. Asp.net sites as a result don't use simple HTML markup code and things like a simple hyper-link to drive the web site. There are no "links" for each row, but only code on the server side that runs to pull the data from the database, and then render that information, and THEN send it down as a html markup.
The bottom line?
The site is not simply HTML and simple hyper-links that you click on. When you click on that button, then the code behind (written in a nice language like c# or vb.net) runs. There is thus no markup code or even JavaScript code that is required here. You talking about clean and nice server side code. (and code written in a fantastic IDE - Visual Studio).
This means that aspx web sites are code behind driven, and as a result they are rather difficult to web scape in a automated fashion. You can get/grab the page you are on, but since there are no hyper-links to the additonal data (such as details), then you don't have a simple URL to follow/trace here.
Worse yet, the setup code (what occurs when you selected a single row) also in most cases has to be run. Only if all values are setup 100% correctly BEFORE hitting the "details" button will this thus work. And even worse, if you note, on the details page, there is no parameters in the URL. This means that not only is code behind required to run BEFORE the 2nd details page launches, but the correct setup code behind has to run. And even worse yet, is the 2nd page URL VERY likely also checks and ensures that the previous URL page was from the same site (as a result you can NOT JUST type in a url for the 2nd page - it will not work.
And in fact, if you look even closer? When you hit details button, the web pages re-loads, re-plots and renders what is CLEARLY a whole new web page and layout.
But note how the URL DOES NOT change!!! They are NOT even using a iframe for this.
This is because they are using what is called a server side re-direct. The key "tell tell" sign is that the URL remains the same, but the whole page layout is 100% different. What occurred is the server side did a re-direct to a 100% whole new page. But since the browser did not and was not causing this navigation? The code behind actually loads + displays a whole new web page and sends it down to the web client side.
However, note how the URL remains the same!!! This is due to the code behind is loading + displaying a whole new different web page - but since the navigation to that new page occurred with server side code?
Well then the server can load + send out anything it wants to the client - include a whole new web page, and you don't get nor see a web url change.
Again, this is typical of asp.net systems in which server side code drives the web site, and not much client side code.
You "might" be able to automate scraping. But you would need some custom code to select a given row, and then some code to click the details button. And that's going to be a REAL challenge, since any changes to the web page code (by you) also tend to be check for, and not allow server side.
The only practical web scrape approach would be to use some desktop tools to create a WHOLE instance of the web browser, let you the user navigate to the given web page that displays the data, and then hit some "capture" button in your application that now reads and parses out the data like you doing now for the main page.

How to code an "create new employees" button

I'm building a web application as an apprentice developer, and I'm stuck completely on how to have this "add information" button? Would it need to be in a <table>?
Hmmm that's quite a vague question but I will try and help and give you a direction to Google things.
You might want to add a input button to your html for the user to click on. When the user clicks on the button you call a technology called JQuery which can then pass information from the client to the server via a technology called AJAX. AJAX can pass information from text fields of your new employees to the server.
Now in the code behind you can then call stored procedures and edit your database.
If you google the bolded text you should get a bit further with your endeavor.
Good Luck!
P.s I am from a C# ASP.net back ground.

ASP.NET and XML for each hit to website

I have a question to understand the concept of ASP.NET with each client browser.
I am trying to update the XML on server when a user hits a particular page on my website.
This page is dynamic, but too large so I want it to load using an XML file also I have several drop downs on the page when user changes the value in drop down, I need to refresh the data based upon the selection, additionally my drop down is a custom designed here I do not get and selectedIndex change event.
So I'm using JQuery to get the changed value in my drop down and planning to read XML from jQuery and display the data.
But since the XML is updated on hit of the page on server, I want know, if multiple users hit the same page, will the data displayed as per each users selection or it will mix the data and show the last hits record.
If I'm not mistaken about your question, you basically ask the following:
You have an XML file, which is updated, on some event from user. The page, which is displayed to the user is based on this XML file. What info will users see, when multiple users are working with the application?
This greatly depends on how you are using that file. In general, if you try to write that file to disk each time, users will see the last update. Basically update from the last user.
However, you can synchronize access to this file, write the file on per-user basis and you will see a per-user output:
<data>
<selectedData user="user name">123</selectedData>
<!-- and so on -->
</data>
UPDATE:
For anonymous users this would not work well. However, if you need to store the selection only for the current user, you can use SessionState and not an XML file.
I would like to introduce a new way that it helped me to answer my above question.
What i did here is
on Page load we added all the information related to each section in different hidden fields.
suppose i have three section with my custom drop down!
What exactly we implemented is that on click on my custom drop-down, we separated the values from the hidden field with the separator we entered and displayed the data accordingly, small part of logic but it helped in displaying the data without post back.
and Jquery helps a lot to me for just changing the inner html of my block.

How do I retrieve HTML dynamically generated from an aspx page?

To be specific, here is what I am doing, and here is what I am trying to do:
I'm coding an ASP.NET page, with VB code behind. When the user clicks a button on the page, I send them an email with information and instructions. Rather than sending a plain text email, I send a nice, pretty, HTML-formatted one. Right now, I'm doing this in a way that I KNOW will be difficult to maintain. That is, I'm straight up writing out all of the html. i.e.
markup += "<fieldset>"
markup += "<legend>"
markup += "Required Documents"
markup += "</legend>"
...and so on. Is there a way to create an aspx page (with vb code behind), and send the html of that page in the body of the email? The information is dynamic, so this pseudo-page would need logic in the on-load event to format the html correctly.
Thanks!
WebClient client = new WebClient ();
string html = client.DownloadString("http://domain.com/emailtemplate.aspx?id=1");
If you have access to a database you can always drop the html in there otherwise, I solved this problem by creating a mailtemplate.html file with [replace] sections in it so all you have to do is read the file into a string object do your replaces and then send it out. If you have to you can maintain multiple templates this way. I use it mostly as a wrapper on emails my systems need to send out so my template has a [body] tag in it that gets replaced with whatever message I need to send. I have also used this method to wrap multiple files into a single email output.
I assume you want to build the html on the fly... One (certainly the most maintainable) solution is to build a template based system.
Technically you maintain your html (e.g. email shots) in a directory read the templates from your ASP.NET program, fill in the details and send the html mail to the user.

Retrieving image from sql database by its path

I have a database where i have the physical path where image of a person is stored .
now i want a code by which I can display the image of that person in a aspx window.
as I am new to asp.net & C#
can somebody provide me the full code of aspx page and the C# code behind it?
Here's a good example on how to connect to a database and display the data in ASP.NET: How to: Bind to Data in a Templated Control on MSDN.
Also there a lots of great tutorials on the ASP.NET "official" site.
Update:
Alright, now we got something to work with. Do you know if your HttpHandler is throwing any exceptions? Place a breakpoint in the HttpHandler code and hit F5 (Visual Studio) to launch the site in debug bug mode. Maybe you're not passing an image ID to the handler? Try and hardcode an ID in the .aspx for an image you know that exists in the database.
See if you can update your question and format the code: Just select the code sample and click the "code" button in the editor. It will indent the text and apply nice formatting, making it easier to read.
Also include your .aspx page so we can see what's going on there.

Resources