Showing posts with label contents. Show all posts
Showing posts with label contents. Show all posts

Wednesday, March 21, 2012

Populating a control with HTML file contents, images included?

publicvoid LoadToLabel()
{
using (StreamReader rdr =newStreamReader(FileUpload1.PostedFile.FileName))
{
string uploadedHTML = rdr.ReadToEnd();
textLabel.Text = uploadedHTML.ToString();
}
}

So far I have that, but the problem is that if the HTML file has an image displayed in it, the image doesn't show up because it's just copying the text. How would I be able to transfer the entire HTML page to a control? Like a panel or something like that, is it possible? And have the images come with it?

You should use LiteralControl for this purpose.


So if I switch it to a literal would it display the images as well?


I just switched it to a literal control and it still ignores the images. What must I do?


Yup. The LiteralControl will display the HTML exactly as you create it. See it as a place holder for output you create from code behind. Good luck!


OK, let me get this straight. You upload a HTML document containing <img> tags, which you then want to print out in the page, right?

If you do a view source in the resulting page, how does it look?

If the image urls in the uploaded page are relative then that is maybe what's causing the problem. Please give an example of how this tag looks like.

Also, if you upload a complete HTML document (with head/body) then you will render a page that is not valid (containing duplicate elements).


What does image urls being relative mean? Like pointing to a specific spot and not "~/Images/image.gif" etc.?

I did a view source on the page that uploads and displays the HTML document and yes you're right, there are now duplicate elements. It uploads everything within the uploaded documents <HTML></HTML> tags. How do I go about just grabbing what's in the body, and not the body tags themselves as that would be a duplicate element as well?


A relative path is one that does not begin with a / or http://something, example:

<img src="http://pics.10026.com/?src=images/ticker.gif">

A relative path is always calculated from the place where it is accessed.

If your (uploaded) page contains relative image paths, then to display these images correctly, you need to either rebuild the path (by parsing), or copy the contents of the path into the same folder as your upload page (not a viable solution).

Or you could make sure the user uploads all the images as well.

In either way, you have some parsing to do in order to get the uploaded file to display correctly. Also you must parse the file to get the actual contents of the file, and get past <html><body> and so on.

One option you have is to show the uploaded file in an iframe which would allow you to show the document as-is (although images would still require parsing).


How would I go about parsing the uploaded file so it displays properly with the images included within the literal control?


Strange... I could almost see that question comingWink Well, parsing text is not trivial, and I am not able to give you the code as it would take some time to develop and test. But here's how I would do: Define a regexp, that finds <img tags, and then replaces the src value with your "path prefixed" value.

Problem is that these tags can come in so many flavours, it's almost impossible to guarantee that the parser matches them correctly. Parsing HTML is kind of re-inventing the wheel again (the wheel being the browser ;-)

Uhm, I'm sorry, can't help you any further with this. But if you google a little on Regular expressions and spend some time trialing and erroring then you might reach your goal. Good luck!


Thank you so much for your help!

Populating a dropdown control

I am trying to populate a drop down on a form with the contents of a
recordset and I am getting the following values in the dropdown
System.Data.DataRowView and not the expected content that should be
appearing in there. I have stepped through the code in debug mode and
examine the value of the recordset, and the right values seem to be there.
Any idea what is causing this and how to fix it so that it does not show up
like this?
.ResetParameters()
.AddParameter("iMRN", OleDb.OleDbType.Integer, ParameterDirection.Input,
ctlHeader.PatientData("PatientMRN"))
'Pull back the list of encounters for the selected patient
If .Execute(.genuSql.StoreProcSelect, "selPatient_Billing") Then
Dim oRow As DataRow
oData = .DbData_DataTable
If .DbData_DataTable.Rows.Count > 0 Then
With drpEnc
.DataSource = oData
.DataBind()
.DataValueField = "id"
.DataTextField = "DateOfService"
End With
End If
Else
Throw New Exception(.ErrorMessage)
End If 'Encounter List
J.Daly
structure:interactive
Ph: 616-364-7423
Fx: 616-364-6941
http://www.structureinteractive.comSe the DataText and DataVauleField properties BEFORE the DataBind().
DataBind() binds your source to your control, setting what to bind after
doesn't work :)
Karl
"Irishmaninusa"
<jdaly@.structuctureinteractive.com.takemeoffifyouwantoemailme> wrote in
message news:u3boxQ3iEHA.2992@.TK2MSFTNGP12.phx.gbl...
> I am trying to populate a drop down on a form with the contents of a
> recordset and I am getting the following values in the dropdown
> System.Data.DataRowView and not the expected content that should be
> appearing in there. I have stepped through the code in debug mode and
> examine the value of the recordset, and the right values seem to be there.
> Any idea what is causing this and how to fix it so that it does not show
up
> like this?
>
>
> .ResetParameters()
> .AddParameter("iMRN", OleDb.OleDbType.Integer, ParameterDirection.Input,
> ctlHeader.PatientData("PatientMRN"))
> 'Pull back the list of encounters for the selected patient
> If .Execute(.genuSql.StoreProcSelect, "selPatient_Billing") Then
> Dim oRow As DataRow
> oData = .DbData_DataTable
>
> If .DbData_DataTable.Rows.Count > 0 Then
> With drpEnc
> .DataSource = oData
> .DataBind()
> .DataValueField = "id"
> .DataTextField = "DateOfService"
> End With
> End If
> Else
> Throw New Exception(.ErrorMessage)
> End If 'Encounter List
>
> --
> J.Daly
> structure:interactive
> Ph: 616-364-7423
> Fx: 616-364-6941
> http://www.structureinteractive.com
>
>
I thought I had did that before and it still didn't work, but I tried it
again and this time it work. Now I have different issue, the stored
procedure I call pulls back date values in order, where the most recent date
is at the top and it goes back in order.
7/28/2004
7/1/2004
6/30/2004
This is the where the stored procedure pulls back the dates, which is
correct. However in the drop down it is being displayed as
7/28/2004
6/30/2004
7/1/2004
Why would this be like this?
"Karl" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:OzuKbe3iEHA.636@.TK2MSFTNGP12.phx.gbl...
> Se the DataText and DataVauleField properties BEFORE the DataBind().
> DataBind() binds your source to your control, setting what to bind after
> doesn't work :)
> Karl
> "Irishmaninusa"
> <jdaly@.structuctureinteractive.com.takemeoffifyouwantoemailme> wrote in
> message news:u3boxQ3iEHA.2992@.TK2MSFTNGP12.phx.gbl...
there.
> up
>
I honestly don't know. I can see that you are using OLEdbClient which I'm
no expert at. Are these Date fields or string/varchar fields? you may want
to start a new thread asking this question and identifying the
database/query/schema so that someone better suited will help.
Karl
"Irishmaninusa"
<jdaly@.structuctureinteractive.com.takemeoffifyouwantoemailme> wrote in
message news:e2sIEo3iEHA.536@.TK2MSFTNGP11.phx.gbl...
> I thought I had did that before and it still didn't work, but I tried it
> again and this time it work. Now I have different issue, the stored
> procedure I call pulls back date values in order, where the most recent
date
> is at the top and it goes back in order.
> 7/28/2004
> 7/1/2004
> 6/30/2004
> This is the where the stored procedure pulls back the dates, which is
> correct. However in the drop down it is being displayed as
>
> 7/28/2004
> 6/30/2004
> 7/1/2004
> Why would this be like this?
> "Karl" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
> message news:OzuKbe3iEHA.636@.TK2MSFTNGP12.phx.gbl...
> there.
show
ParameterDirection.Input,
>
Thanks Karl, I will see what turns up. Thank you for your help to my earlier
issue.
"Karl" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:umG6hJ4iEHA.1376@.TK2MSFTNGP11.phx.gbl...
> I honestly don't know. I can see that you are using OLEdbClient which I'm
> no expert at. Are these Date fields or string/varchar fields? you may
want
> to start a new thread asking this question and identifying the
> database/query/schema so that someone better suited will help.
> Karl
> "Irishmaninusa"
> <jdaly@.structuctureinteractive.com.takemeoffifyouwantoemailme> wrote in
> message news:e2sIEo3iEHA.536@.TK2MSFTNGP11.phx.gbl...
> date
in
after
in
and
> show
> ParameterDirection.Input,
>

Populating a dropdown control

I am trying to populate a drop down on a form with the contents of a
recordset and I am getting the following values in the dropdown

System.Data.DataRowView and not the expected content that should be
appearing in there. I have stepped through the code in debug mode and
examine the value of the recordset, and the right values seem to be there.

Any idea what is causing this and how to fix it so that it does not show up
like this?

..ResetParameters()

..AddParameter("iMRN", OleDb.OleDbType.Integer, ParameterDirection.Input,
ctlHeader.PatientData("PatientMRN"))

'Pull back the list of encounters for the selected patient

If .Execute(.genuSql.StoreProcSelect, "selPatient_Billing") Then

Dim oRow As DataRow

oData = .DbData_DataTable

If .DbData_DataTable.Rows.Count > 0 Then

With drpEnc

..DataSource = oData

..DataBind()

..DataValueField = "id"

..DataTextField = "DateOfService"

End With

End If

Else

Throw New Exception(.ErrorMessage)

End If 'Encounter List

--
J.Daly
structure:interactive
Ph: 616-364-7423
Fx: 616-364-6941

http://www.structureinteractive.comSe the DataText and DataVauleField properties BEFORE the DataBind().

DataBind() binds your source to your control, setting what to bind after
doesn't work :)

Karl

"Irishmaninusa"
<jdaly@.structuctureinteractive.com.takemeoffifyouwa ntoemailme> wrote in
message news:u3boxQ3iEHA.2992@.TK2MSFTNGP12.phx.gbl...
> I am trying to populate a drop down on a form with the contents of a
> recordset and I am getting the following values in the dropdown
> System.Data.DataRowView and not the expected content that should be
> appearing in there. I have stepped through the code in debug mode and
> examine the value of the recordset, and the right values seem to be there.
> Any idea what is causing this and how to fix it so that it does not show
up
> like this?
>
>
> .ResetParameters()
> .AddParameter("iMRN", OleDb.OleDbType.Integer, ParameterDirection.Input,
> ctlHeader.PatientData("PatientMRN"))
> 'Pull back the list of encounters for the selected patient
> If .Execute(.genuSql.StoreProcSelect, "selPatient_Billing") Then
> Dim oRow As DataRow
> oData = .DbData_DataTable
>
> If .DbData_DataTable.Rows.Count > 0 Then
> With drpEnc
> .DataSource = oData
> .DataBind()
> .DataValueField = "id"
> .DataTextField = "DateOfService"
> End With
> End If
> Else
> Throw New Exception(.ErrorMessage)
> End If 'Encounter List
>
> --
> J.Daly
> structure:interactive
> Ph: 616-364-7423
> Fx: 616-364-6941
> http://www.structureinteractive.com
I thought I had did that before and it still didn't work, but I tried it
again and this time it work. Now I have different issue, the stored
procedure I call pulls back date values in order, where the most recent date
is at the top and it goes back in order.

7/28/2004
7/1/2004
6/30/2004

This is the where the stored procedure pulls back the dates, which is
correct. However in the drop down it is being displayed as

7/28/2004
6/30/2004
7/1/2004

Why would this be like this?

"Karl" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:OzuKbe3iEHA.636@.TK2MSFTNGP12.phx.gbl...
> Se the DataText and DataVauleField properties BEFORE the DataBind().
> DataBind() binds your source to your control, setting what to bind after
> doesn't work :)
> Karl
> "Irishmaninusa"
> <jdaly@.structuctureinteractive.com.takemeoffifyouwa ntoemailme> wrote in
> message news:u3boxQ3iEHA.2992@.TK2MSFTNGP12.phx.gbl...
> > I am trying to populate a drop down on a form with the contents of a
> > recordset and I am getting the following values in the dropdown
> > System.Data.DataRowView and not the expected content that should be
> > appearing in there. I have stepped through the code in debug mode and
> > examine the value of the recordset, and the right values seem to be
there.
> > Any idea what is causing this and how to fix it so that it does not show
> up
> > like this?
> > .ResetParameters()
> > .AddParameter("iMRN", OleDb.OleDbType.Integer, ParameterDirection.Input,
> > ctlHeader.PatientData("PatientMRN"))
> > 'Pull back the list of encounters for the selected patient
> > If .Execute(.genuSql.StoreProcSelect, "selPatient_Billing") Then
> > Dim oRow As DataRow
> > oData = .DbData_DataTable
> > If .DbData_DataTable.Rows.Count > 0 Then
> > With drpEnc
> > .DataSource = oData
> > .DataBind()
> > .DataValueField = "id"
> > .DataTextField = "DateOfService"
> > End With
> > End If
> > Else
> > Throw New Exception(.ErrorMessage)
> > End If 'Encounter List
> > --
> > J.Daly
> > structure:interactive
> > Ph: 616-364-7423
> > Fx: 616-364-6941
> > http://www.structureinteractive.com
I honestly don't know. I can see that you are using OLEdbClient which I'm
no expert at. Are these Date fields or string/varchar fields? you may want
to start a new thread asking this question and identifying the
database/query/schema so that someone better suited will help.

Karl

"Irishmaninusa"
<jdaly@.structuctureinteractive.com.takemeoffifyouwa ntoemailme> wrote in
message news:e2sIEo3iEHA.536@.TK2MSFTNGP11.phx.gbl...
> I thought I had did that before and it still didn't work, but I tried it
> again and this time it work. Now I have different issue, the stored
> procedure I call pulls back date values in order, where the most recent
date
> is at the top and it goes back in order.
> 7/28/2004
> 7/1/2004
> 6/30/2004
> This is the where the stored procedure pulls back the dates, which is
> correct. However in the drop down it is being displayed as
>
> 7/28/2004
> 6/30/2004
> 7/1/2004
> Why would this be like this?
> "Karl" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
> message news:OzuKbe3iEHA.636@.TK2MSFTNGP12.phx.gbl...
> > Se the DataText and DataVauleField properties BEFORE the DataBind().
> > DataBind() binds your source to your control, setting what to bind after
> > doesn't work :)
> > Karl
> > "Irishmaninusa"
> > <jdaly@.structuctureinteractive.com.takemeoffifyouwa ntoemailme> wrote in
> > message news:u3boxQ3iEHA.2992@.TK2MSFTNGP12.phx.gbl...
> > > I am trying to populate a drop down on a form with the contents of a
> > > recordset and I am getting the following values in the dropdown
> > > > System.Data.DataRowView and not the expected content that should be
> > > appearing in there. I have stepped through the code in debug mode and
> > > examine the value of the recordset, and the right values seem to be
> there.
> > > > Any idea what is causing this and how to fix it so that it does not
show
> > up
> > > like this?
> > > > > > > > .ResetParameters()
> > > > .AddParameter("iMRN", OleDb.OleDbType.Integer,
ParameterDirection.Input,
> > > ctlHeader.PatientData("PatientMRN"))
> > > > 'Pull back the list of encounters for the selected patient
> > > > If .Execute(.genuSql.StoreProcSelect, "selPatient_Billing") Then
> > > > Dim oRow As DataRow
> > > > oData = .DbData_DataTable
> > > > > > If .DbData_DataTable.Rows.Count > 0 Then
> > > > With drpEnc
> > > > .DataSource = oData
> > > > .DataBind()
> > > > .DataValueField = "id"
> > > > .DataTextField = "DateOfService"
> > > > End With
> > > > End If
> > > > Else
> > > > Throw New Exception(.ErrorMessage)
> > > > End If 'Encounter List
> > > > > --
> > > J.Daly
> > > structure:interactive
> > > Ph: 616-364-7423
> > > Fx: 616-364-6941
> > > > http://www.structureinteractive.com
> > >
Thanks Karl, I will see what turns up. Thank you for your help to my earlier
issue.

"Karl" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:umG6hJ4iEHA.1376@.TK2MSFTNGP11.phx.gbl...
> I honestly don't know. I can see that you are using OLEdbClient which I'm
> no expert at. Are these Date fields or string/varchar fields? you may
want
> to start a new thread asking this question and identifying the
> database/query/schema so that someone better suited will help.
> Karl
> "Irishmaninusa"
> <jdaly@.structuctureinteractive.com.takemeoffifyouwa ntoemailme> wrote in
> message news:e2sIEo3iEHA.536@.TK2MSFTNGP11.phx.gbl...
> > I thought I had did that before and it still didn't work, but I tried it
> > again and this time it work. Now I have different issue, the stored
> > procedure I call pulls back date values in order, where the most recent
> date
> > is at the top and it goes back in order.
> > 7/28/2004
> > 7/1/2004
> > 6/30/2004
> > This is the where the stored procedure pulls back the dates, which is
> > correct. However in the drop down it is being displayed as
> > 7/28/2004
> > 6/30/2004
> > 7/1/2004
> > Why would this be like this?
> > "Karl" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net> wrote
in
> > message news:OzuKbe3iEHA.636@.TK2MSFTNGP12.phx.gbl...
> > > Se the DataText and DataVauleField properties BEFORE the DataBind().
> > > > DataBind() binds your source to your control, setting what to bind
after
> > > doesn't work :)
> > > > Karl
> > > > "Irishmaninusa"
> > > <jdaly@.structuctureinteractive.com.takemeoffifyouwa ntoemailme> wrote
in
> > > message news:u3boxQ3iEHA.2992@.TK2MSFTNGP12.phx.gbl...
> > > > I am trying to populate a drop down on a form with the contents of a
> > > > recordset and I am getting the following values in the dropdown
> > > > > > System.Data.DataRowView and not the expected content that should be
> > > > appearing in there. I have stepped through the code in debug mode
and
> > > > examine the value of the recordset, and the right values seem to be
> > there.
> > > > > > Any idea what is causing this and how to fix it so that it does not
> show
> > > up
> > > > like this?
> > > > > > > > > > > > > > .ResetParameters()
> > > > > > .AddParameter("iMRN", OleDb.OleDbType.Integer,
> ParameterDirection.Input,
> > > > ctlHeader.PatientData("PatientMRN"))
> > > > > > 'Pull back the list of encounters for the selected patient
> > > > > > If .Execute(.genuSql.StoreProcSelect, "selPatient_Billing") Then
> > > > > > Dim oRow As DataRow
> > > > > > oData = .DbData_DataTable
> > > > > > > > > > If .DbData_DataTable.Rows.Count > 0 Then
> > > > > > With drpEnc
> > > > > > .DataSource = oData
> > > > > > .DataBind()
> > > > > > .DataValueField = "id"
> > > > > > .DataTextField = "DateOfService"
> > > > > > End With
> > > > > > End If
> > > > > > Else
> > > > > > Throw New Exception(.ErrorMessage)
> > > > > > End If 'Encounter List
> > > > > > > > --
> > > > J.Daly
> > > > structure:interactive
> > > > Ph: 616-364-7423
> > > > Fx: 616-364-6941
> > > > > > http://www.structureinteractive.com
> > > > > > > >