Retrieving image from sql database by its path - asp.net

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.

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.

Have text file; need to search and extract to website

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

Embed WinForms in ASP.NET application

I need to make an upload application. ASP.NET already has an UploadFile control. But there is one more requirement: to be able to select a folder and to upload all his content. So I need to create an FolderBrowse control to be able to select a folder. Becase the SelectFile dialog that is included in UploadFile control looks so professional the DirectoryBrowse should look the same. I google it and found 2 solution: 1. to create in windows form a control that opena a file and opens a folder and gives the consumer the selected path.... and 2. it was something with using interop to be able to use a .net folderBrowse control ....not very clear to me this one that's why I tried to create an windows forms control and embed it in web site. The problem is:
1.
In designer I got an text over the control : The control type was not specified or the specified type could not be found.
in browser I see a little rectangle where the control should be.
If I add type = application then in browser I see nothing at all.
In win forms control I set for the user control:
[ComVisible(true)]
Can someone give me a clue please? what I am doing wrong? Or maybe another solution?

Webform not displaying

I have to port an application to .NET, so I decided to go with ASP Webforms.
I have my sample database (which is empty) set up and I have a few webforms (GridView, DetailsView). For a 'new' record page, I have a DetailView, but when I run it the server doesnt serve any form. I suspect it is because the tables are empty, so how do I set it up so it renders the form so I can add a New record.
Thanks, Also if anyone could point me to a good Webforms tutorial that covers the basics it would be great. Google has millions of those but most of them, including the msdn are cumbersome and get into lots of details that confuse me.
What I had to do in this case is use the <EmptyDataTemplate> Field. This happens because when the DataSet is empty, the Form doesnt renders anything unless it's specified in the EmptyDataTemplate.

Checkboxes in ASP.NET

I am trying to use a checkbox that is dynamically declared in an .vb file that I am trying to write into my .aspx page. I am able to write a normal checkbox of <input type='checkbox /> from the .vb Class using Response.write, but it comes up blank when using <asp:Checkbox runat='server' />I need to pass whether or not the box is checked back to the server, because I am having to either approve something if one is checked, reject something if the other is checked or do nothing if neither are checked. I have figured out how to make them mutually exclusive either way so that is not the problem. Does anyone have any recommendations?
Your problem lies in the order that the pages are compiled in: When you place an asp control like the asp:checkbox, it is compiled into a regular checkbox with some javascript attached when it is sent over to the client.
When you write the string "<input type='checkbox />" to the page from the code-behind it is writing that string directly to the page, after the aspx page has compiled its controls, but since that is valid html the browser renders the control. When you write the asp:checkbox, the browser doesn't know what to do with it, because it is not valid html. In addition, the page has already been compiled, so there is no chance of .net creating the correct control for you.
You need to programmatic add the control to the webpage by creating a new control through the code behind
This site does a great job explaining it
And #toodles seems spot on. Writing static html and asp.net are two totally different ball games. I would spend a bit of time (like hours/days) reading/watching learning material to help you get on your feet.
The technical answers you are getting are all good. However, your question indicates that you really need to start by learning how asp.net server controls work. I suggest spending a couple hours watching the videos at http://asp.net and particularly http://www.asp.net/general/videos/intro-to-aspnet-controls
Then focus on understanding the page lifecycle and you'll have enough of the basics to be much more effective at asp.net. Have fun!
You can't use response.write to create server controls.
See this site for an example of the right way to do it:
http://msdn.microsoft.com/en-us/library/kyt0fzt1.aspx

Resources