Showing posts with label text. Show all posts
Showing posts with label text. Show all posts

Saturday, March 31, 2012

server side code access the text of <asp:label> changed by client-side javascript co

Is possible for server side code to access the text of <asp:label> changed
by client side javascript code?Yes, of course you can do it.

--
-Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com

"nick" <nbdy9.removethis@.hotmail.com> wrote in message
news:%23UAnyAt4EHA.2600@.TK2MSFTNGP09.phx.gbl...
> Is possible for server side code to access the text of <asp:label> changed
> by client side javascript code?
No, you will need to double the new value into a hidden text field, or some
other postable field, and then look for the change of the text through the
Request.Forms["txtHidden1"] property on postback to determine if the text
has changed.

bill

"nick" <nbdy9.removethis@.hotmail.com> wrote in message
news:%23UAnyAt4EHA.2600@.TK2MSFTNGP09.phx.gbl...
> Is possible for server side code to access the text of <asp:label> changed
> by client side javascript code?
If you mean accessing the text via the label's Text property, the answer is
no.

You can pass the changed text to the server in one of the common ways of
passing values from client to server, for example in a hidden field.

Eliyahu

"nick" <nbdy9.removethis@.hotmail.com> wrote in message
news:%23UAnyAt4EHA.2600@.TK2MSFTNGP09.phx.gbl...
> Is possible for server side code to access the text of <asp:label> changed
> by client side javascript code?

server side code access the text of <asp:label> changed by client-side javascri

Is possible for server side code to access the text of <asp:label> changed
by client side javascript code?Yes, of course you can do it.
-Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"nick" <nbdy9.removethis@.hotmail.com> wrote in message
news:%23UAnyAt4EHA.2600@.TK2MSFTNGP09.phx.gbl...
> Is possible for server side code to access the text of <asp:label> changed
> by client side javascript code?
>
No, you will need to double the new value into a hidden text field, or some
other postable field, and then look for the change of the text through the
Request.Forms["txtHidden1"] property on postback to determine if the text
has changed.
bill
"nick" <nbdy9.removethis@.hotmail.com> wrote in message
news:%23UAnyAt4EHA.2600@.TK2MSFTNGP09.phx.gbl...
> Is possible for server side code to access the text of <asp:label> changed
> by client side javascript code?
>
If you mean accessing the text via the label's Text property, the answer is
no.
You can pass the changed text to the server in one of the common ways of
passing values from client to server, for example in a hidden field.
Eliyahu
"nick" <nbdy9.removethis@.hotmail.com> wrote in message
news:%23UAnyAt4EHA.2600@.TK2MSFTNGP09.phx.gbl...
> Is possible for server side code to access the text of <asp:label> changed
> by client side javascript code?
>

Server Side FieldSet?

I'm trying to write a Web Custom control that allows me to generate a set of server side text boxes inside the fieldset element. What I have is this:

protectedoverridevoid Render(HtmlTextWriter output)

{

StringBuilder sb =new StringBuilder();

//Begin the FieldSet if it's needed

if (this.ShowBorder )

sb.Append(string.Format("<fieldset style='WIDTH: {0}; HEIGHT: {1}'><legend>{2}</legend>",this.Width,this.Height,this.Legend));

//Add user controls

for(int i = 0; i <this.SearchFormFields.Length; i++)

{

SearchField curField =this.SearchFormFields[i];sb.Append(string.Format("<span class='fwifont'>{0}</span><br>", curField.Title));

//sb.Append(string.Format("<FWI:MultiRangeTextBox CssClass='fwifont' id=AccountNumberBox runat='server' TermName='{0}'></FWI:MultiRangeTextBox>", curField.TermName));

sb.Append("<asp:TextBox Runat='server' ID='fsdfd'></asp:TextBox>");

}

sb.Append("<br>");

//Finish off fieldset

if (this.ShowBorder )

sb.Append("</fieldset>");

sb.Append("<br>");

output.Write(sb.ToString());

}

However, the asp:text box does not render or show up. I'm guessing this has something to do with the fact that it's a server side control itself. Does anyone have any ideas on what I'm doing wrong here?

You are trying to output ASP control tags as markup. Would something like "<input type="text" id=......" rather the the ASP textbox control be more suitable?

Ta


Most unfortuantely, no, I cannot use html input fields. And actually, it not only needs to be a server side control, in reality it should be a custom web control that actually extends the asp:textbox class. I have a method that traverses all the controls on the web forms and handles the input of each textbox based on what "type" of server side text box it is.

Server side HTML printing

Hi,
I am using a rich text editor (FCKEdit) on a webpage in which user can
enter formatted text.
The output of this control is HTML. Now on the code behind side, I need
to change some of this HTML and then print the HTML (the pretty
document - not the code) on the server printer.
Any ideas'
Thanks in advance<sprash25@.gmail.com> wrote in message
news:1149837637.843058.67720@.i39g2000cwa.googlegroups.com...
> Hi,
> I am using a rich text editor (FCKEdit) on a webpage in which user can
> enter formatted text.
> The output of this control is HTML. Now on the code behind side, I need
> to change some of this HTML and then print the HTML (the pretty
> document - not the code) on the server printer.
> Any ideas'
> Thanks in advance
>
Well, I can help you with the capture of the html side. The printing is
another matter. This code will capture the html just before it get sent to
the client. You also google for 'asp.net output html save'
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
Dim _stringBuilder As StringBuilder = New StringBuilder()
Dim _stringWriter As StringWriter = New StringWriter(_stringBuilder)
Dim _htmlWriter As HtmlTextWriter = New HtmlTextWriter(_stringWriter)
MyBase.Render(_htmlWriter)
Dim html As String = _stringBuilder.ToString()
'here is where you can manipulate or save to file or database or maybe print
the html output string
writer.Write(html) 'this writes the page back out
End Sub
Mike

Server side HTML printing

Hi,

I am using a rich text editor (FCKEdit) on a webpage in which user can
enter formatted text.
The output of this control is HTML. Now on the code behind side, I need
to change some of this HTML and then print the HTML (the pretty
document - not the code) on the server printer.

Any ideas??

Thanks in advance<sprash25@.gmail.com> wrote in message
news:1149837637.843058.67720@.i39g2000cwa.googlegro ups.com...
> Hi,
> I am using a rich text editor (FCKEdit) on a webpage in which user can
> enter formatted text.
> The output of this control is HTML. Now on the code behind side, I need
> to change some of this HTML and then print the HTML (the pretty
> document - not the code) on the server printer.
> Any ideas??
> Thanks in advance
Well, I can help you with the capture of the html side. The printing is
another matter. This code will capture the html just before it get sent to
the client. You also google for 'asp.net output html save'

Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)

Dim _stringBuilder As StringBuilder = New StringBuilder()
Dim _stringWriter As StringWriter = New StringWriter(_stringBuilder)
Dim _htmlWriter As HtmlTextWriter = New HtmlTextWriter(_stringWriter)
MyBase.Render(_htmlWriter)

Dim html As String = _stringBuilder.ToString()

'here is where you can manipulate or save to file or database or maybe print
the html output string

writer.Write(html) 'this writes the page back out

End Sub

Mike

Thursday, March 29, 2012

Server side preview of IE rendering...

I am writing an ASP.NET tool that will allow the client to create their own
online froms. ie the client can add tect boxes, text, drop downs,etc with
absolutely no technical skill what so ever. The form can then be deployed to
their intranet.
The form designer is somewhat WYSIWYG but it contains a heap of 'edit',
'delete' and reordering buttons that are not seen when the form is acutally
being used.
I would love to have a preview image of what the form will actually look
like when it has been rendered in IE and display it in the form designer.
Much like a the print preview in Word.
I figure that my server would need some component that would acutally render
the page in some invisible IE and then take a screen shot of the web page
and then return the image. The designer could then hyperlink to that image
so the use could see a preview.
Another option would be to have an embedded frame but to adjust its 'zoom'
to be very small. Unfortunately frames do not support such a mythical
'zoom' feature.
Does any one have any idea about how I might solve this problem?
The poor mans option is to have a Preview button in the designer that will
lauch a new browser window and display the form but I am trying to steer
away form this.
Regards
Dave AHi Dave,
If I understand you right, you want to show a preview of the form to your
user, right? How are you rendering the final HTML? Are you using ASP.NET
server controls? Or are you just rendering straight HTML? If you are just
rendering straight HTML, you can update a <div> tag or <asp:Label> control
with your final HTML. You can do this on the server-side by simply
instantiating a HtmlGenericControl for your div tag and updating its
InnerHtml property with your final HTML...i.e. something like this:
<div ID="PreviewPanel" runat="server">
</div>
And in your server code:
// optional, depending on if you are using ASP.NET 2.0 or not
public HtmlGenericControl PreviewPanel;
[C#]
string finalHtml = "..."; // set this to your application generates
PreviewPanel.InnerHtml = finalHtml;
Voila, you are now rendering the HTML on the page. Just make sure to do this
upon every refresh, i.e. after every time your client updates something on
the page.
If you want to do something more complicated, i.e. render the ASP.NET server
controls, let me know.
Joshua Mitts
joshrm@.msn.com
"Dave A" <dave@.sigmasolutionsdonotspamme.com.au> wrote in message
news:%23YRXaa23FHA.2424@.TK2MSFTNGP10.phx.gbl...
>I am writing an ASP.NET tool that will allow the client to create their own
>online froms. ie the client can add tect boxes, text, drop downs,etc with
>absolutely no technical skill what so ever. The form can then be deployed
>to their intranet.
> The form designer is somewhat WYSIWYG but it contains a heap of 'edit',
> 'delete' and reordering buttons that are not seen when the form is
> acutally being used.
> I would love to have a preview image of what the form will actually look
> like when it has been rendered in IE and display it in the form designer.
> Much like a the print preview in Word.
> I figure that my server would need some component that would acutally
> render the page in some invisible IE and then take a screen shot of the
> web page and then return the image. The designer could then hyperlink to
> that image so the use could see a preview.
> Another option would be to have an embedded frame but to adjust its 'zoom'
> to be very small. Unfortunately frames do not support such a mythical
> 'zoom' feature.
> Does any one have any idea about how I might solve this problem?
> The poor mans option is to have a Preview button in the designer that will
> lauch a new browser window and display the form but I am trying to steer
> away form this.
> Regards
> Dave A
>
Sorry - I should have been more clear. I want a thumbnail representation of
what the page will actually look like.
Regards
Dave
"Josh Mitts" <joshrm@.msn.com> wrote in message
news:eO%235Ps23FHA.3880@.TK2MSFTNGP12.phx.gbl...
> Hi Dave,
> If I understand you right, you want to show a preview of the form to your
> user, right? How are you rendering the final HTML? Are you using ASP.NET
> server controls? Or are you just rendering straight HTML? If you are just
> rendering straight HTML, you can update a <div> tag or <asp:Label> control
> with your final HTML. You can do this on the server-side by simply
> instantiating a HtmlGenericControl for your div tag and updating its
> InnerHtml property with your final HTML...i.e. something like this:
> <div ID="PreviewPanel" runat="server">
> </div>
> And in your server code:
> // optional, depending on if you are using ASP.NET 2.0 or not
> public HtmlGenericControl PreviewPanel;
> [C#]
> string finalHtml = "..."; // set this to your application generates
> PreviewPanel.InnerHtml = finalHtml;
> Voila, you are now rendering the HTML on the page. Just make sure to do
> this upon every refresh, i.e. after every time your client updates
> something on the page.
> If you want to do something more complicated, i.e. render the ASP.NET
> server controls, let me know.
> --
> Joshua Mitts
> joshrm@.msn.com
>
> "Dave A" <dave@.sigmasolutionsdonotspamme.com.au> wrote in message
> news:%23YRXaa23FHA.2424@.TK2MSFTNGP10.phx.gbl...
>
Here you go
Daniel Fisher(lennybacon)
http://www.lennybacon.com
using System;
using System.IO;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
// Interop
using AxSHDocVw;
using mshtml;
using SHDocVw;
namespace StaticDust
{
/// <summary>
/// Converts HTML documents to PNG format.
/// </summary>
public class Html2Image : System.Windows.Forms.UserControl
{
private AxSHDocVw.AxWebBrowser m_IE;
private System.ComponentModel.Container m_Components = null;
#region Html2Image()
private Html2Image()
{
// setups our embedded ie control
InitializeComponent();
}
#endregion
#region Convert()
/// <summary>
/// Converts a HTML file to a PNG file(s).
/// </summary>
/// <param name="url">A string with the url of the HTML file that should
be converted.</param>
/// <param name="pageLength">A int with the heigth of the PNG file(s).
Use -1 to capture the full HTML file.</param>
/// <param name="outputDir">A <see cref="System.String">string</see> with
the path of the directory, where the PNG file(s) should be saved.</param>
/// <param name="outputFile">A <see cref="System.String">string</see> with
the name of the PNG file(s).</param>
/// <returns>An array with filenames of the created PNG file(s).</returns>
/// <remarks>This method converts a HTML file to PNG file(s).</remarks>
public static String[] Convert(string url, int pageLength, string
outputDir, string outputFile)
{
Html2Image _html2Image = new Html2Image();
_html2Image.CreateControl();
string[] _f = _html2Image.CreateFiles(url, pageLength, outputDir,
outputFile);
_html2Image.Dispose();
return _f;
}
#endregion
#region CreateFiles()
private string[] CreateFiles(string url, int pageLength, string outputDir,
string outputFile)
{
while(!m_IE.Created)
{
Application.DoEvents();
}
object _arg1 = 0;
object _arg2 = "";
object _arg3 = "";
object _arg4 = "";
m_IE.Navigate(url, ref _arg1, ref _arg2, ref _arg3, ref _arg4);
while(!this.m_DocComplete)
{
Application.DoEvents();
}
Application.DoEvents();
while(GetHtmlBody() == null)
{
Application.DoEvents();
}
Application.DoEvents();
m_DocComplete = false;
m_IE.Navigate(url, ref _arg1, ref _arg2, ref _arg3, ref _arg4);
while(!this.m_DocComplete)
{
Application.DoEvents();
}
Application.DoEvents();
while(GetHtmlBody() == null)
{
Application.DoEvents();
}
Application.DoEvents();
for(int i=0; i<2000000; i++)
{
Application.DoEvents();
}
m_DocComplete = false;
m_IE.Navigate(url, ref _arg1, ref _arg2, ref _arg3, ref _arg4);
while(!this.m_DocComplete)
{
Application.DoEvents();
}
Application.DoEvents();
for(int i=0; i<2000000; i++)
{
Application.DoEvents();
}
while(GetHtmlBody() == null)
{
Application.DoEvents();
}
Application.DoEvents();
Bitmap _htmlimage = CaptureImage();
if (_htmlimage!=null)
{
if(pageLength==-1)
{
pageLength = _htmlimage.Height;
}
Bitmap _pageBitmap = new Bitmap(_htmlimage.Width, pageLength);
Graphics _g = Graphics.FromImage(_pageBitmap);
int _p = (int)Math.Floor(_htmlimage.Height/pageLength);
if(_p*pageLength<_htmlimage.Height)
{
_p++;
}
string[] _files = new string[_p];
for (int i=0;i<_files.GetLength(0);i++)
{
_g.Clear(Color.White);
_g.DrawImage(_htmlimage, new Rectangle(0, 0, _pageBitmap.Width,
pageLength), new Rectangle(0, (i*pageLength), _pageBitmap.Width,
pageLength), GraphicsUnit.Pixel);
_files[i] = Path.Combine(outputDir, outputFile+i+".png");
_pageBitmap.Save(_files[i], ImageFormat.Png);
}
_htmlimage.Dispose();
_g.Dispose();
_pageBitmap.Dispose();
return _files;
}
return null;
}
#endregion
#region OnDocumentComplete()
private bool m_DocComplete = false;
private void OnDocumentComplete(object sender,
AxSHDocVw. DWebBrowserEvents2_DocumentCompleteEvent
e)
{
m_DocComplete = true;
}
#endregion
#region CaptureImage()
private Bitmap CaptureImage()
{
try
{
IHTMLElement2 _htmlBody2 = GetHtmlBody();
Application.DoEvents();
int _w = _htmlBody2.scrollWidth;
int _h = _htmlBody2.scrollHeight;
// Make our embedded ie control that size
if((m_IE.Height != _h + 30) || (m_IE.Width != _w + 30))
{
m_IE.Height = _h + 30;
m_IE.Width = _w + 30;
}
// Setup bitmap memory and wrap a DC around it
Bitmap _bitmap = new Bitmap(_w, _h, PixelFormat.Format24bppRgb);
Graphics _graphics = Graphics.FromImage(_bitmap);
IntPtr _memdc = _graphics.GetHdc();
IntPtr _hbitmap = _bitmap.GetHbitmap();
SelectObject(_memdc, _hbitmap);
// Tell ie to print into our dc/bitmap
// Use PrintWindow windows api
//
const uint PW_CLIENTONLY = 0x00000001;
//
bool _rv = PrintWindow(m_IE.Handle, _memdc, PW_CLIENTONLY);
// Send it a print msg + flags
const uint WM_PRINT = 0x0317;
// const uint WM_PRINTCLIENT = 0x0318;
// const uint PRF_CHECKVISIBLE = 0x00000001;
const uint PRF_NONCLIENT = 0x00000002;
const uint PRF_CLIENT = 0x00000004;
const uint PRF_ERASEBKGND = 0x00000008;
const uint PRF_CHILDREN = 0x00000010;
const uint PRF_OWNED = 0x00000020;
int _err = SendMessage(m_IE.Handle, WM_PRINT, (uint)_memdc, (uint)
(PRF_CLIENT | PRF_NONCLIENT | PRF_OWNED | PRF_CHILDREN | PRF_ERASEBKGND));
// Save image
Bitmap _bitmap2 = Bitmap.FromHbitmap(_hbitmap);
// Cleanup
DeleteObject(_hbitmap);
_graphics.ReleaseHdc(_memdc);
_graphics.Dispose();
_bitmap.Dispose();
return _bitmap2;
}
catch(Exception ex)
{
System.Console.WriteLine("Exception: " + ex.Message + "\n");
System.Console.WriteLine(" source: " + ex.Source + "\n");
System.Console.WriteLine(" stacktrace:" + ex.StackTrace + "\n");
throw;
}
}
#endregion
#region Dispose()
/// <summary>
/// Releases the unmanaged resources used by the Control and its child
controls and optionally releases the managed resources.
/// </summary>
/// <param name="disposing"><b>true</b> to release both managed and
unmanaged resources; <b>false</b> to release only unmanaged resources.
</param>
/// <remarks>
/// This method is called by the public Dispose() method and the Finalize
method. <b>Dispose()</b>
/// invokes the protected <b>Dispose(Boolean)</b> method with
/// the <i>disposing</i> parameter set to <b>true</b>. <b>Finalize</b>
invokes <b>Dispose</b> with <i>disposing</i> set to <b>false</b>.
/// <br/>When the <i>disposing</i> parameter is <b>true</b>, this method
releases all resources held by any managed
/// objects that this Control and its child controls reference. This
method invokes the <b>Dispose()</b>
/// method of each referenced object.
/// <br/><b>Notes to Inheritors:</b> <b>Dispose</b> can be called
multiple times by other objects. When overriding
/// <b>Dispose(Boolean)</b>, be careful not to reference objects that have
been previously disposed of in
/// an earlier call to <b>Dispose</b>.
/// </remarks>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(m_Components != null)
{
m_Components.Dispose();
}
}
base.Dispose( disposing );
}
#endregion
#region InitializeComponent()
private void InitializeComponent()
{
System.Resources.ResourceManager _resources = new
System.Resources.ResourceManager(typeof(Html2Image));
this.m_IE = new AxSHDocVw.AxWebBrowser();
((System.ComponentModel.ISupportInitialize)(this.m_IE)).BeginInit();
this.SuspendLayout();
//
// m_IE
//
this.m_IE.Enabled = true;
this.m_IE.Location = new System.Drawing.Point(0, 0);
//this.m_IE.OcxState =
((System.Windows.Forms.AxHost.State)(resources.GetObject("m_IE.OcxState")));
this.m_IE.Size = new System.Drawing.Size(804, 580);
this.m_IE.TabIndex = 7;
this.m_IE.DocumentComplete += new
AxSHDocVw. DWebBrowserEvents2_DocumentCompleteEvent
Handler(this.OnDocumentCom
plete);
//
// Html2Image
//
this.Controls.AddRange(new System.Windows.Forms.Control[] { this.m_IE});
this.Size = new System.Drawing.Size(292, 266);
((System.ComponentModel.ISupportInitialize)(this.m_IE)).EndInit();
this.ResumeLayout(false);
}
#endregion
//IE InterOp
#region IHTMLElement2 GetHtmlBody()
private IHTMLElement2 GetHtmlBody()
{
IWebBrowser2 _wb2 = (IWebBrowser2) m_IE.GetOcx();
Application.DoEvents();
IHTMLDocument2 _htmlDocument2 = (IHTMLDocument2) _wb2.Document;
Application.DoEvents();
return (IHTMLElement2)_htmlDocument2.body;
}
#endregion
//Win32 InterOp
#region extern IntPtr SelectObject()
[DllImport("Gdi32.dll")]
private static extern IntPtr SelectObject(
IntPtr hdc, // handle to DC
IntPtr hgdiobj // handle to object
);
#endregion
#region extern bool DeleteObject()
[DllImport("Gdi32.dll")]
private static extern bool DeleteObject(
IntPtr hObject // handle to graphic object
);
#endregion
#region extern IntPtr CreateCompatibleDC()
[DllImport("Gdi32.dll")]
private static extern IntPtr CreateCompatibleDC(
IntPtr hdc // handle to DC
);
#endregion
#region extern bool DeleteDC()
[DllImport("Gdi32.dll")]
private static extern bool DeleteDC(
IntPtr hdc // handle to DC
);
#endregion
#region extern bool PrintWindow()
[DllImport("User32.dll")]
private static extern bool PrintWindow(
IntPtr hwnd, // Window to copy
IntPtr hdcBlt, // HDC to print into
uint nFlags // Optional flags // must contain PW_CLIENTONLY
);
#endregion
#region extern int SendMessage()
[DllImport("User32.dll")]
private static extern int SendMessage(
IntPtr hWnd, // handle to destination window
uint Msg, // message
uint wParam, // firstmessage parameter
uint lParam // second message parameter
);
#endregion
}
}
"Dave A" <dave@.sigmasolutionsdonotspamme.com.au> wrote in message
news:eIhiZOF4FHA.3628@.TK2MSFTNGP12.phx.gbl...
> Sorry - I should have been more clear. I want a thumbnail representation
> of what the page will actually look like.
> Regards
> Dave
> "Josh Mitts" <joshrm@.msn.com> wrote in message
> news:eO%235Ps23FHA.3880@.TK2MSFTNGP12.phx.gbl...
>
Holy crap! Well done man! I would never have worked this out and thought
that it was impossible. I am pleased that I asked.
Regards
Dave
"Daniel Fisher(lennybacon)" <info@.lennybacon.com> wrote in message
news:OHj8PjF4FHA.3628@.TK2MSFTNGP12.phx.gbl...
> Here you go
> --
> Daniel Fisher(lennybacon)
> http://www.lennybacon.com
> using System;
> using System.IO;
> using System.Collections;
> using System.ComponentModel;
> using System.Drawing;
> using System.Data;
> using System.Windows.Forms;
> using System.Drawing.Imaging;
> using System.Runtime.InteropServices;
> // Interop
> using AxSHDocVw;
> using mshtml;
> using SHDocVw;
> namespace StaticDust
> {
> /// <summary>
> /// Converts HTML documents to PNG format.
> /// </summary>
> public class Html2Image : System.Windows.Forms.UserControl
> {
> private AxSHDocVw.AxWebBrowser m_IE;
> private System.ComponentModel.Container m_Components = null;
> #region Html2Image()
> private Html2Image()
> {
> // setups our embedded ie control
> InitializeComponent();
> }
> #endregion
> #region Convert()
> /// <summary>
> /// Converts a HTML file to a PNG file(s).
> /// </summary>
> /// <param name="url">A string with the url of the HTML file that should
> be converted.</param>
> /// <param name="pageLength">A int with the heigth of the PNG file(s).
> Use -1 to capture the full HTML file.</param>
> /// <param name="outputDir">A <see cref="System.String">string</see> with
> the path of the directory, where the PNG file(s) should be saved.</param>
> /// <param name="outputFile">A <see cref="System.String">string</see>
> with the name of the PNG file(s).</param>
> /// <returns>An array with filenames of the created PNG
> file(s).</returns>
> /// <remarks>This method converts a HTML file to PNG file(s).</remarks>
> public static String[] Convert(string url, int pageLength, string
> outputDir, string outputFile)
> {
> Html2Image _html2Image = new Html2Image();
> _html2Image.CreateControl();
> string[] _f = _html2Image.CreateFiles(url, pageLength, outputDir,
> outputFile);
> _html2Image.Dispose();
> return _f;
> }
> #endregion
> #region CreateFiles()
> private string[] CreateFiles(string url, int pageLength, string
> outputDir, string outputFile)
> {
> while(!m_IE.Created)
> {
> Application.DoEvents();
> }
> object _arg1 = 0;
> object _arg2 = "";
> object _arg3 = "";
> object _arg4 = "";
> m_IE.Navigate(url, ref _arg1, ref _arg2, ref _arg3, ref _arg4);
> while(!this.m_DocComplete)
> {
> Application.DoEvents();
> }
> Application.DoEvents();
> while(GetHtmlBody() == null)
> {
> Application.DoEvents();
> }
> Application.DoEvents();
> m_DocComplete = false;
> m_IE.Navigate(url, ref _arg1, ref _arg2, ref _arg3, ref _arg4);
> while(!this.m_DocComplete)
> {
> Application.DoEvents();
> }
> Application.DoEvents();
> while(GetHtmlBody() == null)
> {
> Application.DoEvents();
> }
> Application.DoEvents();
> for(int i=0; i<2000000; i++)
> {
> Application.DoEvents();
> }
> m_DocComplete = false;
> m_IE.Navigate(url, ref _arg1, ref _arg2, ref _arg3, ref _arg4);
> while(!this.m_DocComplete)
> {
> Application.DoEvents();
> }
> Application.DoEvents();
> for(int i=0; i<2000000; i++)
> {
> Application.DoEvents();
> }
> while(GetHtmlBody() == null)
> {
> Application.DoEvents();
> }
> Application.DoEvents();
>
> Bitmap _htmlimage = CaptureImage();
> if (_htmlimage!=null)
> {
> if(pageLength==-1)
> {
> pageLength = _htmlimage.Height;
> }
> Bitmap _pageBitmap = new Bitmap(_htmlimage.Width, pageLength);
> Graphics _g = Graphics.FromImage(_pageBitmap);
> int _p = (int)Math.Floor(_htmlimage.Height/pageLength);
> if(_p*pageLength<_htmlimage.Height)
> {
> _p++;
> }
> string[] _files = new string[_p];
> for (int i=0;i<_files.GetLength(0);i++)
> {
> _g.Clear(Color.White);
> _g.DrawImage(_htmlimage, new Rectangle(0, 0, _pageBitmap.Width,
> pageLength), new Rectangle(0, (i*pageLength), _pageBitmap.Width,
> pageLength), GraphicsUnit.Pixel);
> _files[i] = Path.Combine(outputDir, outputFile+i+".png");
> _pageBitmap.Save(_files[i], ImageFormat.Png);
> }
> _htmlimage.Dispose();
> _g.Dispose();
> _pageBitmap.Dispose();
> return _files;
> }
> return null;
> }
> #endregion
> #region OnDocumentComplete()
> private bool m_DocComplete = false;
> private void OnDocumentComplete(object sender,
> AxSHDocVw. DWebBrowserEvents2_DocumentCompleteEvent
e)
> {
> m_DocComplete = true;
> }
> #endregion
>
> #region CaptureImage()
> private Bitmap CaptureImage()
> {
> try
> {
> IHTMLElement2 _htmlBody2 = GetHtmlBody();
> Application.DoEvents();
> int _w = _htmlBody2.scrollWidth;
> int _h = _htmlBody2.scrollHeight;
> // Make our embedded ie control that size
> if((m_IE.Height != _h + 30) || (m_IE.Width != _w + 30))
> {
> m_IE.Height = _h + 30;
> m_IE.Width = _w + 30;
> }
> // Setup bitmap memory and wrap a DC around it
> Bitmap _bitmap = new Bitmap(_w, _h, PixelFormat.Format24bppRgb);
> Graphics _graphics = Graphics.FromImage(_bitmap);
> IntPtr _memdc = _graphics.GetHdc();
> IntPtr _hbitmap = _bitmap.GetHbitmap();
> SelectObject(_memdc, _hbitmap);
> // Tell ie to print into our dc/bitmap
> // Use PrintWindow windows api
> //
> const uint PW_CLIENTONLY = 0x00000001;
> //
> bool _rv = PrintWindow(m_IE.Handle, _memdc, PW_CLIENTONLY);
> // Send it a print msg + flags
> const uint WM_PRINT = 0x0317;
> // const uint WM_PRINTCLIENT = 0x0318;
> // const uint PRF_CHECKVISIBLE = 0x00000001;
> const uint PRF_NONCLIENT = 0x00000002;
> const uint PRF_CLIENT = 0x00000004;
> const uint PRF_ERASEBKGND = 0x00000008;
> const uint PRF_CHILDREN = 0x00000010;
> const uint PRF_OWNED = 0x00000020;
> int _err = SendMessage(m_IE.Handle, WM_PRINT, (uint)_memdc, (uint)
> (PRF_CLIENT | PRF_NONCLIENT | PRF_OWNED | PRF_CHILDREN | PRF_ERASEBKGND));
> // Save image
> Bitmap _bitmap2 = Bitmap.FromHbitmap(_hbitmap);
> // Cleanup
> DeleteObject(_hbitmap);
> _graphics.ReleaseHdc(_memdc);
> _graphics.Dispose();
> _bitmap.Dispose();
> return _bitmap2;
> }
> catch(Exception ex)
> {
> System.Console.WriteLine("Exception: " + ex.Message + "\n");
> System.Console.WriteLine(" source: " + ex.Source + "\n");
> System.Console.WriteLine(" stacktrace:" + ex.StackTrace + "\n");
> throw;
> }
> }
> #endregion
>
> #region Dispose()
> /// <summary>
> /// Releases the unmanaged resources used by the Control and its child
> controls and optionally releases the managed resources.
> /// </summary>
> /// <param name="disposing"><b>true</b> to release both managed and
> unmanaged resources; <b>false</b> to release only unmanaged resources.
> </param>
> /// <remarks>
> /// This method is called by the public Dispose() method and the Finalize
> method. <b>Dispose()</b>
> /// invokes the protected <b>Dispose(Boolean)</b> method with
> /// the <i>disposing</i> parameter set to <b>true</b>. <b>Finalize</b>
> invokes <b>Dispose</b> with <i>disposing</i> set to <b>false</b>.
> /// <br/>When the <i>disposing</i> parameter is <b>true</b>, this method
> releases all resources held by any managed
> /// objects that this Control and its child controls reference. This
> method invokes the <b>Dispose()</b>
> /// method of each referenced object.
> /// <br/><b>Notes to Inheritors:</b> <b>Dispose</b> can be called
> multiple times by other objects. When overriding
> /// <b>Dispose(Boolean)</b>, be careful not to reference objects that
> have been previously disposed of in
> /// an earlier call to <b>Dispose</b>.
> /// </remarks>
> protected override void Dispose( bool disposing )
> {
> if( disposing )
> {
> if(m_Components != null)
> {
> m_Components.Dispose();
> }
> }
> base.Dispose( disposing );
> }
> #endregion
> #region InitializeComponent()
> private void InitializeComponent()
> {
> System.Resources.ResourceManager _resources = new
> System.Resources.ResourceManager(typeof(Html2Image));
> this.m_IE = new AxSHDocVw.AxWebBrowser();
> ((System.ComponentModel.ISupportInitialize)(this.m_IE)).BeginInit();
> this.SuspendLayout();
> //
> // m_IE
> //
> this.m_IE.Enabled = true;
> this.m_IE.Location = new System.Drawing.Point(0, 0);
> //this.m_IE.OcxState =
> ((System.Windows.Forms.AxHost.State)(resources.GetObject("m_IE.OcxState"))
);
> this.m_IE.Size = new System.Drawing.Size(804, 580);
> this.m_IE.TabIndex = 7;
> this.m_IE.DocumentComplete += new
> AxSHDocVw. DWebBrowserEvents2_DocumentCompleteEvent
Handler(this.OnDocumentC
omplete);
> //
> // Html2Image
> //
> this.Controls.AddRange(new System.Windows.Forms.Control[] { this.m_IE});
> this.Size = new System.Drawing.Size(292, 266);
> ((System.ComponentModel.ISupportInitialize)(this.m_IE)).EndInit();
> this.ResumeLayout(false);
> }
> #endregion
>
> //IE InterOp
> #region IHTMLElement2 GetHtmlBody()
> private IHTMLElement2 GetHtmlBody()
> {
> IWebBrowser2 _wb2 = (IWebBrowser2) m_IE.GetOcx();
> Application.DoEvents();
> IHTMLDocument2 _htmlDocument2 = (IHTMLDocument2) _wb2.Document;
> Application.DoEvents();
> return (IHTMLElement2)_htmlDocument2.body;
> }
> #endregion
>
> //Win32 InterOp
> #region extern IntPtr SelectObject()
> [DllImport("Gdi32.dll")]
> private static extern IntPtr SelectObject(
> IntPtr hdc, // handle to DC
> IntPtr hgdiobj // handle to object
> );
> #endregion
> #region extern bool DeleteObject()
> [DllImport("Gdi32.dll")]
> private static extern bool DeleteObject(
> IntPtr hObject // handle to graphic object
> );
> #endregion
> #region extern IntPtr CreateCompatibleDC()
> [DllImport("Gdi32.dll")]
> private static extern IntPtr CreateCompatibleDC(
> IntPtr hdc // handle to DC
> );
> #endregion
> #region extern bool DeleteDC()
> [DllImport("Gdi32.dll")]
> private static extern bool DeleteDC(
> IntPtr hdc // handle to DC
> );
> #endregion
> #region extern bool PrintWindow()
> [DllImport("User32.dll")]
> private static extern bool PrintWindow(
> IntPtr hwnd, // Window to copy
> IntPtr hdcBlt, // HDC to print into
> uint nFlags // Optional flags // must contain
> PW_CLIENTONLY
> );
> #endregion
> #region extern int SendMessage()
> [DllImport("User32.dll")]
> private static extern int SendMessage(
> IntPtr hWnd, // handle to destination window
> uint Msg, // message
> uint wParam, // firstmessage parameter
> uint lParam // second message parameter
> );
> #endregion
> }
> }
>
> "Dave A" <dave@.sigmasolutionsdonotspamme.com.au> wrote in message
> news:eIhiZOF4FHA.3628@.TK2MSFTNGP12.phx.gbl...
>
Will this work with .Net 2.0 ?
Do any special references need to be added to the project?
--Alex

Server side preview of IE rendering...

I am writing an ASP.NET tool that will allow the client to create their own
online froms. ie the client can add tect boxes, text, drop downs,etc with
absolutely no technical skill what so ever. The form can then be deployed to
their intranet.

The form designer is somewhat WYSIWYG but it contains a heap of 'edit',
'delete' and reordering buttons that are not seen when the form is acutally
being used.

I would love to have a preview image of what the form will actually look
like when it has been rendered in IE and display it in the form designer.
Much like a the print preview in Word.

I figure that my server would need some component that would acutally render
the page in some invisible IE and then take a screen shot of the web page
and then return the image. The designer could then hyperlink to that image
so the use could see a preview.

Another option would be to have an embedded frame but to adjust its 'zoom'
to be very small. Unfortunately frames do not support such a mythical
'zoom' feature.

Does any one have any idea about how I might solve this problem?

The poor mans option is to have a Preview button in the designer that will
lauch a new browser window and display the form but I am trying to steer
away form this.

Regards
Dave AHi Dave,

If I understand you right, you want to show a preview of the form to your
user, right? How are you rendering the final HTML? Are you using ASP.NET
server controls? Or are you just rendering straight HTML? If you are just
rendering straight HTML, you can update a <div> tag or <asp:Label> control
with your final HTML. You can do this on the server-side by simply
instantiating a HtmlGenericControl for your div tag and updating its
InnerHtml property with your final HTML...i.e. something like this:

<div ID="PreviewPanel" runat="server">
</div
And in your server code:

// optional, depending on if you are using ASP.NET 2.0 or not
public HtmlGenericControl PreviewPanel;

[C#]
string finalHtml = "..."; // set this to your application generates
PreviewPanel.InnerHtml = finalHtml;

Voila, you are now rendering the HTML on the page. Just make sure to do this
upon every refresh, i.e. after every time your client updates something on
the page.

If you want to do something more complicated, i.e. render the ASP.NET server
controls, let me know.

--

Joshua Mitts
joshrm@.msn.com

"Dave A" <dave@.sigmasolutionsdonotspamme.com.au> wrote in message
news:%23YRXaa23FHA.2424@.TK2MSFTNGP10.phx.gbl...
>I am writing an ASP.NET tool that will allow the client to create their own
>online froms. ie the client can add tect boxes, text, drop downs,etc with
>absolutely no technical skill what so ever. The form can then be deployed
>to their intranet.
> The form designer is somewhat WYSIWYG but it contains a heap of 'edit',
> 'delete' and reordering buttons that are not seen when the form is
> acutally being used.
> I would love to have a preview image of what the form will actually look
> like when it has been rendered in IE and display it in the form designer.
> Much like a the print preview in Word.
> I figure that my server would need some component that would acutally
> render the page in some invisible IE and then take a screen shot of the
> web page and then return the image. The designer could then hyperlink to
> that image so the use could see a preview.
> Another option would be to have an embedded frame but to adjust its 'zoom'
> to be very small. Unfortunately frames do not support such a mythical
> 'zoom' feature.
> Does any one have any idea about how I might solve this problem?
> The poor mans option is to have a Preview button in the designer that will
> lauch a new browser window and display the form but I am trying to steer
> away form this.
> Regards
> Dave A
Sorry - I should have been more clear. I want a thumbnail representation of
what the page will actually look like.

Regards
Dave

"Josh Mitts" <joshrm@.msn.com> wrote in message
news:eO%235Ps23FHA.3880@.TK2MSFTNGP12.phx.gbl...
> Hi Dave,
> If I understand you right, you want to show a preview of the form to your
> user, right? How are you rendering the final HTML? Are you using ASP.NET
> server controls? Or are you just rendering straight HTML? If you are just
> rendering straight HTML, you can update a <div> tag or <asp:Label> control
> with your final HTML. You can do this on the server-side by simply
> instantiating a HtmlGenericControl for your div tag and updating its
> InnerHtml property with your final HTML...i.e. something like this:
> <div ID="PreviewPanel" runat="server">
> </div>
> And in your server code:
> // optional, depending on if you are using ASP.NET 2.0 or not
> public HtmlGenericControl PreviewPanel;
> [C#]
> string finalHtml = "..."; // set this to your application generates
> PreviewPanel.InnerHtml = finalHtml;
> Voila, you are now rendering the HTML on the page. Just make sure to do
> this upon every refresh, i.e. after every time your client updates
> something on the page.
> If you want to do something more complicated, i.e. render the ASP.NET
> server controls, let me know.
> --
> Joshua Mitts
> joshrm@.msn.com
>
> "Dave A" <dave@.sigmasolutionsdonotspamme.com.au> wrote in message
> news:%23YRXaa23FHA.2424@.TK2MSFTNGP10.phx.gbl...
>>I am writing an ASP.NET tool that will allow the client to create their
>>own online froms. ie the client can add tect boxes, text, drop downs,etc
>>with absolutely no technical skill what so ever. The form can then be
>>deployed to their intranet.
>>
>> The form designer is somewhat WYSIWYG but it contains a heap of 'edit',
>> 'delete' and reordering buttons that are not seen when the form is
>> acutally being used.
>>
>> I would love to have a preview image of what the form will actually look
>> like when it has been rendered in IE and display it in the form designer.
>> Much like a the print preview in Word.
>>
>> I figure that my server would need some component that would acutally
>> render the page in some invisible IE and then take a screen shot of the
>> web page and then return the image. The designer could then hyperlink to
>> that image so the use could see a preview.
>>
>> Another option would be to have an embedded frame but to adjust its
>> 'zoom' to be very small. Unfortunately frames do not support such a
>> mythical 'zoom' feature.
>>
>> Does any one have any idea about how I might solve this problem?
>>
>> The poor mans option is to have a Preview button in the designer that
>> will lauch a new browser window and display the form but I am trying to
>> steer away form this.
>>
>> Regards
>> Dave A
>>
>>
Here you go

--
Daniel Fisher(lennybacon)
http://www.lennybacon.com

using System;
using System.IO;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;

// Interop
using AxSHDocVw;
using mshtml;
using SHDocVw;

namespace StaticDust
{
/// <summary>
/// Converts HTML documents to PNG format.
/// </summary>
public class Html2Image : System.Windows.Forms.UserControl
{
private AxSHDocVw.AxWebBrowser m_IE;
private System.ComponentModel.Container m_Components = null;

#region Html2Image()
private Html2Image()
{
// setups our embedded ie control
InitializeComponent();
}
#endregion

#region Convert()
/// <summary>
/// Converts a HTML file to a PNG file(s).
/// </summary>
/// <param name="url">A string with the url of the HTML file that should
be converted.</param>
/// <param name="pageLength">A int with the heigth of the PNG file(s).
Use -1 to capture the full HTML file.</param>
/// <param name="outputDir">A <see cref="System.String">string</see> with
the path of the directory, where the PNG file(s) should be saved.</param>
/// <param name="outputFile">A <see cref="System.String">string</see> with
the name of the PNG file(s).</param>
/// <returns>An array with filenames of the created PNG file(s).</returns>
/// <remarks>This method converts a HTML file to PNG file(s).</remarks>
public static String[] Convert(string url, int pageLength, string
outputDir, string outputFile)
{

Html2Image _html2Image = new Html2Image();
_html2Image.CreateControl();
string[] _f = _html2Image.CreateFiles(url, pageLength, outputDir,
outputFile);
_html2Image.Dispose();
return _f;
}
#endregion

#region CreateFiles()
private string[] CreateFiles(string url, int pageLength, string outputDir,
string outputFile)
{
while(!m_IE.Created)
{
Application.DoEvents();
}

object _arg1 = 0;
object _arg2 = "";
object _arg3 = "";
object _arg4 = "";
m_IE.Navigate(url, ref _arg1, ref _arg2, ref _arg3, ref _arg4);

while(!this.m_DocComplete)
{
Application.DoEvents();
}
Application.DoEvents();

while(GetHtmlBody() == null)
{
Application.DoEvents();
}
Application.DoEvents();

m_DocComplete = false;
m_IE.Navigate(url, ref _arg1, ref _arg2, ref _arg3, ref _arg4);
while(!this.m_DocComplete)
{
Application.DoEvents();
}
Application.DoEvents();

while(GetHtmlBody() == null)
{
Application.DoEvents();
}
Application.DoEvents();

for(int i=0; i<2000000; i++)
{
Application.DoEvents();
}

m_DocComplete = false;
m_IE.Navigate(url, ref _arg1, ref _arg2, ref _arg3, ref _arg4);
while(!this.m_DocComplete)
{
Application.DoEvents();
}
Application.DoEvents();

for(int i=0; i<2000000; i++)
{
Application.DoEvents();
}

while(GetHtmlBody() == null)
{
Application.DoEvents();
}
Application.DoEvents();

Bitmap _htmlimage = CaptureImage();

if (_htmlimage!=null)
{
if(pageLength==-1)
{
pageLength = _htmlimage.Height;
}

Bitmap _pageBitmap = new Bitmap(_htmlimage.Width, pageLength);
Graphics _g = Graphics.FromImage(_pageBitmap);

int _p = (int)Math.Floor(_htmlimage.Height/pageLength);
if(_p*pageLength<_htmlimage.Height)
{
_p++;
}

string[] _files = new string[_p];
for (int i=0;i<_files.GetLength(0);i++)
{
_g.Clear(Color.White);
_g.DrawImage(_htmlimage, new Rectangle(0, 0, _pageBitmap.Width,
pageLength), new Rectangle(0, (i*pageLength), _pageBitmap.Width,
pageLength), GraphicsUnit.Pixel);
_files[i] = Path.Combine(outputDir, outputFile+i+".png");
_pageBitmap.Save(_files[i], ImageFormat.Png);
}

_htmlimage.Dispose();
_g.Dispose();
_pageBitmap.Dispose();
return _files;
}
return null;
}
#endregion

#region OnDocumentComplete()
private bool m_DocComplete = false;
private void OnDocumentComplete(object sender,
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
m_DocComplete = true;
}
#endregion

#region CaptureImage()
private Bitmap CaptureImage()
{
try
{
IHTMLElement2 _htmlBody2 = GetHtmlBody();
Application.DoEvents();
int _w = _htmlBody2.scrollWidth;
int _h = _htmlBody2.scrollHeight;

// Make our embedded ie control that size
if((m_IE.Height != _h + 30) || (m_IE.Width != _w + 30))
{
m_IE.Height = _h + 30;
m_IE.Width = _w + 30;
}

// Setup bitmap memory and wrap a DC around it
Bitmap _bitmap = new Bitmap(_w, _h, PixelFormat.Format24bppRgb);
Graphics _graphics = Graphics.FromImage(_bitmap);
IntPtr _memdc = _graphics.GetHdc();
IntPtr _hbitmap = _bitmap.GetHbitmap();
SelectObject(_memdc, _hbitmap);

// Tell ie to print into our dc/bitmap

// Use PrintWindow windows api
//
const uint PW_CLIENTONLY = 0x00000001;
//
bool _rv = PrintWindow(m_IE.Handle, _memdc, PW_CLIENTONLY);

// Send it a print msg + flags
const uint WM_PRINT = 0x0317;
// const uint WM_PRINTCLIENT = 0x0318;
// const uint PRF_CHECKVISIBLE = 0x00000001;
const uint PRF_NONCLIENT = 0x00000002;
const uint PRF_CLIENT = 0x00000004;
const uint PRF_ERASEBKGND = 0x00000008;
const uint PRF_CHILDREN = 0x00000010;
const uint PRF_OWNED = 0x00000020;
int _err = SendMessage(m_IE.Handle, WM_PRINT, (uint)_memdc, (uint)
(PRF_CLIENT | PRF_NONCLIENT | PRF_OWNED | PRF_CHILDREN | PRF_ERASEBKGND));

// Save image
Bitmap _bitmap2 = Bitmap.FromHbitmap(_hbitmap);

// Cleanup
DeleteObject(_hbitmap);
_graphics.ReleaseHdc(_memdc);
_graphics.Dispose();
_bitmap.Dispose();

return _bitmap2;

}
catch(Exception ex)
{
System.Console.WriteLine("Exception: " + ex.Message + "\n");
System.Console.WriteLine(" source: " + ex.Source + "\n");
System.Console.WriteLine(" stacktrace:" + ex.StackTrace + "\n");
throw;
}

}
#endregion

#region Dispose()
/// <summary>
/// Releases the unmanaged resources used by the Control and its child
controls and optionally releases the managed resources.
/// </summary>
/// <param name="disposing"><b>true</b> to release both managed and
unmanaged resources; <b>false</b> to release only unmanaged resources.
</param>
/// <remarks>
/// This method is called by the public Dispose() method and the Finalize
method. <b>Dispose()</b>
/// invokes the protected <b>Dispose(Boolean)</b> method with
/// the <i>disposing</i> parameter set to <b>true</b>. <b>Finalize</b>
invokes <b>Dispose</b> with <i>disposing</i> set to <b>false</b>.
/// <br/>When the <i>disposing</i> parameter is <b>true</b>, this method
releases all resources held by any managed
/// objects that this Control and its child controls reference. This
method invokes the <b>Dispose()</b>
/// method of each referenced object.
/// <br/><b>Notes to Inheritors:</b> <b>Dispose</b> can be called
multiple times by other objects. When overriding
/// <b>Dispose(Boolean)</b>, be careful not to reference objects that have
been previously disposed of in
/// an earlier call to <b>Dispose</b>.
/// </remarks>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(m_Components != null)
{
m_Components.Dispose();
}
}
base.Dispose( disposing );
}
#endregion

#region InitializeComponent()
private void InitializeComponent()
{
System.Resources.ResourceManager _resources = new
System.Resources.ResourceManager(typeof(Html2Image ));
this.m_IE = new AxSHDocVw.AxWebBrowser();
((System.ComponentModel.ISupportInitialize)(this.m _IE)).BeginInit();
this.SuspendLayout();
//
// m_IE
//
this.m_IE.Enabled = true;
this.m_IE.Location = new System.Drawing.Point(0, 0);
//this.m_IE.OcxState =
((System.Windows.Forms.AxHost.State)(resources.Get Object("m_IE.OcxState")));
this.m_IE.Size = new System.Drawing.Size(804, 580);
this.m_IE.TabIndex = 7;
this.m_IE.DocumentComplete += new
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent Handler(this.OnDocumentComplete);

//
// Html2Image
//
this.Controls.AddRange(new System.Windows.Forms.Control[] { this.m_IE});
this.Size = new System.Drawing.Size(292, 266);
((System.ComponentModel.ISupportInitialize)(this.m _IE)).EndInit();
this.ResumeLayout(false);
}
#endregion

//IE InterOp

#region IHTMLElement2 GetHtmlBody()
private IHTMLElement2 GetHtmlBody()
{
IWebBrowser2 _wb2 = (IWebBrowser2) m_IE.GetOcx();
Application.DoEvents();
IHTMLDocument2 _htmlDocument2 = (IHTMLDocument2) _wb2.Document;
Application.DoEvents();
return (IHTMLElement2)_htmlDocument2.body;
}
#endregion

//Win32 InterOp

#region extern IntPtr SelectObject()
[DllImport("Gdi32.dll")]
private static extern IntPtr SelectObject(
IntPtr hdc, // handle to DC
IntPtr hgdiobj // handle to object
);
#endregion

#region extern bool DeleteObject()
[DllImport("Gdi32.dll")]
private static extern bool DeleteObject(
IntPtr hObject // handle to graphic object
);
#endregion

#region extern IntPtr CreateCompatibleDC()
[DllImport("Gdi32.dll")]
private static extern IntPtr CreateCompatibleDC(
IntPtr hdc // handle to DC
);
#endregion

#region extern bool DeleteDC()
[DllImport("Gdi32.dll")]
private static extern bool DeleteDC(
IntPtr hdc // handle to DC
);
#endregion

#region extern bool PrintWindow()
[DllImport("User32.dll")]
private static extern bool PrintWindow(
IntPtr hwnd, // Window to copy
IntPtr hdcBlt, // HDC to print into
uint nFlags // Optional flags // must contain PW_CLIENTONLY
);
#endregion

#region extern int SendMessage()
[DllImport("User32.dll")]
private static extern int SendMessage(
IntPtr hWnd, // handle to destination window
uint Msg, // message
uint wParam, // firstmessage parameter
uint lParam // second message parameter
);
#endregion

}
}

"Dave A" <dave@.sigmasolutionsdonotspamme.com.au> wrote in message
news:eIhiZOF4FHA.3628@.TK2MSFTNGP12.phx.gbl...
> Sorry - I should have been more clear. I want a thumbnail representation
> of what the page will actually look like.
> Regards
> Dave
> "Josh Mitts" <joshrm@.msn.com> wrote in message
> news:eO%235Ps23FHA.3880@.TK2MSFTNGP12.phx.gbl...
>> Hi Dave,
>>
>> If I understand you right, you want to show a preview of the form to your
>> user, right? How are you rendering the final HTML? Are you using ASP.NET
>> server controls? Or are you just rendering straight HTML? If you are just
>> rendering straight HTML, you can update a <div> tag or <asp:Label>
>> control with your final HTML. You can do this on the server-side by
>> simply instantiating a HtmlGenericControl for your div tag and updating
>> its InnerHtml property with your final HTML...i.e. something like this:
>>
>> <div ID="PreviewPanel" runat="server">
>> </div>
>>
>> And in your server code:
>>
>> // optional, depending on if you are using ASP.NET 2.0 or not
>> public HtmlGenericControl PreviewPanel;
>>
>> [C#]
>> string finalHtml = "..."; // set this to your application generates
>> PreviewPanel.InnerHtml = finalHtml;
>>
>> Voila, you are now rendering the HTML on the page. Just make sure to do
>> this upon every refresh, i.e. after every time your client updates
>> something on the page.
>>
>> If you want to do something more complicated, i.e. render the ASP.NET
>> server controls, let me know.
>>
>> --
>>
>> Joshua Mitts
>> joshrm@.msn.com
>>
>>
>> "Dave A" <dave@.sigmasolutionsdonotspamme.com.au> wrote in message
>> news:%23YRXaa23FHA.2424@.TK2MSFTNGP10.phx.gbl...
>>>I am writing an ASP.NET tool that will allow the client to create their
>>>own online froms. ie the client can add tect boxes, text, drop downs,etc
>>>with absolutely no technical skill what so ever. The form can then be
>>>deployed to their intranet.
>>>
>>> The form designer is somewhat WYSIWYG but it contains a heap of 'edit',
>>> 'delete' and reordering buttons that are not seen when the form is
>>> acutally being used.
>>>
>>> I would love to have a preview image of what the form will actually look
>>> like when it has been rendered in IE and display it in the form
>>> designer. Much like a the print preview in Word.
>>>
>>> I figure that my server would need some component that would acutally
>>> render the page in some invisible IE and then take a screen shot of the
>>> web page and then return the image. The designer could then hyperlink
>>> to that image so the use could see a preview.
>>>
>>> Another option would be to have an embedded frame but to adjust its
>>> 'zoom' to be very small. Unfortunately frames do not support such a
>>> mythical 'zoom' feature.
>>>
>>> Does any one have any idea about how I might solve this problem?
>>>
>>> The poor mans option is to have a Preview button in the designer that
>>> will lauch a new browser window and display the form but I am trying to
>>> steer away form this.
>>>
>>> Regards
>>> Dave A
>>>
>>>
>>
>>
Holy crap! Well done man! I would never have worked this out and thought
that it was impossible. I am pleased that I asked.

Regards
Dave

"Daniel Fisher(lennybacon)" <info@.lennybacon.com> wrote in message
news:OHj8PjF4FHA.3628@.TK2MSFTNGP12.phx.gbl...
> Here you go
> --
> Daniel Fisher(lennybacon)
> http://www.lennybacon.com
> using System;
> using System.IO;
> using System.Collections;
> using System.ComponentModel;
> using System.Drawing;
> using System.Data;
> using System.Windows.Forms;
> using System.Drawing.Imaging;
> using System.Runtime.InteropServices;
> // Interop
> using AxSHDocVw;
> using mshtml;
> using SHDocVw;
> namespace StaticDust
> {
> /// <summary>
> /// Converts HTML documents to PNG format.
> /// </summary>
> public class Html2Image : System.Windows.Forms.UserControl
> {
> private AxSHDocVw.AxWebBrowser m_IE;
> private System.ComponentModel.Container m_Components = null;
> #region Html2Image()
> private Html2Image()
> {
> // setups our embedded ie control
> InitializeComponent();
> }
> #endregion
> #region Convert()
> /// <summary>
> /// Converts a HTML file to a PNG file(s).
> /// </summary>
> /// <param name="url">A string with the url of the HTML file that should
> be converted.</param>
> /// <param name="pageLength">A int with the heigth of the PNG file(s).
> Use -1 to capture the full HTML file.</param>
> /// <param name="outputDir">A <see cref="System.String">string</see> with
> the path of the directory, where the PNG file(s) should be saved.</param>
> /// <param name="outputFile">A <see cref="System.String">string</see>
> with the name of the PNG file(s).</param>
> /// <returns>An array with filenames of the created PNG
> file(s).</returns>
> /// <remarks>This method converts a HTML file to PNG file(s).</remarks>
> public static String[] Convert(string url, int pageLength, string
> outputDir, string outputFile)
> {
> Html2Image _html2Image = new Html2Image();
> _html2Image.CreateControl();
> string[] _f = _html2Image.CreateFiles(url, pageLength, outputDir,
> outputFile);
> _html2Image.Dispose();
> return _f;
> }
> #endregion
> #region CreateFiles()
> private string[] CreateFiles(string url, int pageLength, string
> outputDir, string outputFile)
> {
> while(!m_IE.Created)
> {
> Application.DoEvents();
> }
> object _arg1 = 0;
> object _arg2 = "";
> object _arg3 = "";
> object _arg4 = "";
> m_IE.Navigate(url, ref _arg1, ref _arg2, ref _arg3, ref _arg4);
> while(!this.m_DocComplete)
> {
> Application.DoEvents();
> }
> Application.DoEvents();
> while(GetHtmlBody() == null)
> {
> Application.DoEvents();
> }
> Application.DoEvents();
> m_DocComplete = false;
> m_IE.Navigate(url, ref _arg1, ref _arg2, ref _arg3, ref _arg4);
> while(!this.m_DocComplete)
> {
> Application.DoEvents();
> }
> Application.DoEvents();
> while(GetHtmlBody() == null)
> {
> Application.DoEvents();
> }
> Application.DoEvents();
> for(int i=0; i<2000000; i++)
> {
> Application.DoEvents();
> }
> m_DocComplete = false;
> m_IE.Navigate(url, ref _arg1, ref _arg2, ref _arg3, ref _arg4);
> while(!this.m_DocComplete)
> {
> Application.DoEvents();
> }
> Application.DoEvents();
> for(int i=0; i<2000000; i++)
> {
> Application.DoEvents();
> }
> while(GetHtmlBody() == null)
> {
> Application.DoEvents();
> }
> Application.DoEvents();
>
> Bitmap _htmlimage = CaptureImage();
> if (_htmlimage!=null)
> {
> if(pageLength==-1)
> {
> pageLength = _htmlimage.Height;
> }
> Bitmap _pageBitmap = new Bitmap(_htmlimage.Width, pageLength);
> Graphics _g = Graphics.FromImage(_pageBitmap);
> int _p = (int)Math.Floor(_htmlimage.Height/pageLength);
> if(_p*pageLength<_htmlimage.Height)
> {
> _p++;
> }
> string[] _files = new string[_p];
> for (int i=0;i<_files.GetLength(0);i++)
> {
> _g.Clear(Color.White);
> _g.DrawImage(_htmlimage, new Rectangle(0, 0, _pageBitmap.Width,
> pageLength), new Rectangle(0, (i*pageLength), _pageBitmap.Width,
> pageLength), GraphicsUnit.Pixel);
> _files[i] = Path.Combine(outputDir, outputFile+i+".png");
> _pageBitmap.Save(_files[i], ImageFormat.Png);
> }
> _htmlimage.Dispose();
> _g.Dispose();
> _pageBitmap.Dispose();
> return _files;
> }
> return null;
> }
> #endregion
> #region OnDocumentComplete()
> private bool m_DocComplete = false;
> private void OnDocumentComplete(object sender,
> AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
> {
> m_DocComplete = true;
> }
> #endregion
>
> #region CaptureImage()
> private Bitmap CaptureImage()
> {
> try
> {
> IHTMLElement2 _htmlBody2 = GetHtmlBody();
> Application.DoEvents();
> int _w = _htmlBody2.scrollWidth;
> int _h = _htmlBody2.scrollHeight;
> // Make our embedded ie control that size
> if((m_IE.Height != _h + 30) || (m_IE.Width != _w + 30))
> {
> m_IE.Height = _h + 30;
> m_IE.Width = _w + 30;
> }
> // Setup bitmap memory and wrap a DC around it
> Bitmap _bitmap = new Bitmap(_w, _h, PixelFormat.Format24bppRgb);
> Graphics _graphics = Graphics.FromImage(_bitmap);
> IntPtr _memdc = _graphics.GetHdc();
> IntPtr _hbitmap = _bitmap.GetHbitmap();
> SelectObject(_memdc, _hbitmap);
> // Tell ie to print into our dc/bitmap
> // Use PrintWindow windows api
> //
> const uint PW_CLIENTONLY = 0x00000001;
> //
> bool _rv = PrintWindow(m_IE.Handle, _memdc, PW_CLIENTONLY);
> // Send it a print msg + flags
> const uint WM_PRINT = 0x0317;
> // const uint WM_PRINTCLIENT = 0x0318;
> // const uint PRF_CHECKVISIBLE = 0x00000001;
> const uint PRF_NONCLIENT = 0x00000002;
> const uint PRF_CLIENT = 0x00000004;
> const uint PRF_ERASEBKGND = 0x00000008;
> const uint PRF_CHILDREN = 0x00000010;
> const uint PRF_OWNED = 0x00000020;
> int _err = SendMessage(m_IE.Handle, WM_PRINT, (uint)_memdc, (uint)
> (PRF_CLIENT | PRF_NONCLIENT | PRF_OWNED | PRF_CHILDREN | PRF_ERASEBKGND));
> // Save image
> Bitmap _bitmap2 = Bitmap.FromHbitmap(_hbitmap);
> // Cleanup
> DeleteObject(_hbitmap);
> _graphics.ReleaseHdc(_memdc);
> _graphics.Dispose();
> _bitmap.Dispose();
> return _bitmap2;
> }
> catch(Exception ex)
> {
> System.Console.WriteLine("Exception: " + ex.Message + "\n");
> System.Console.WriteLine(" source: " + ex.Source + "\n");
> System.Console.WriteLine(" stacktrace:" + ex.StackTrace + "\n");
> throw;
> }
> }
> #endregion
>
> #region Dispose()
> /// <summary>
> /// Releases the unmanaged resources used by the Control and its child
> controls and optionally releases the managed resources.
> /// </summary>
> /// <param name="disposing"><b>true</b> to release both managed and
> unmanaged resources; <b>false</b> to release only unmanaged resources.
> </param>
> /// <remarks>
> /// This method is called by the public Dispose() method and the Finalize
> method. <b>Dispose()</b>
> /// invokes the protected <b>Dispose(Boolean)</b> method with
> /// the <i>disposing</i> parameter set to <b>true</b>. <b>Finalize</b>
> invokes <b>Dispose</b> with <i>disposing</i> set to <b>false</b>.
> /// <br/>When the <i>disposing</i> parameter is <b>true</b>, this method
> releases all resources held by any managed
> /// objects that this Control and its child controls reference. This
> method invokes the <b>Dispose()</b>
> /// method of each referenced object.
> /// <br/><b>Notes to Inheritors:</b> <b>Dispose</b> can be called
> multiple times by other objects. When overriding
> /// <b>Dispose(Boolean)</b>, be careful not to reference objects that
> have been previously disposed of in
> /// an earlier call to <b>Dispose</b>.
> /// </remarks>
> protected override void Dispose( bool disposing )
> {
> if( disposing )
> {
> if(m_Components != null)
> {
> m_Components.Dispose();
> }
> }
> base.Dispose( disposing );
> }
> #endregion
> #region InitializeComponent()
> private void InitializeComponent()
> {
> System.Resources.ResourceManager _resources = new
> System.Resources.ResourceManager(typeof(Html2Image ));
> this.m_IE = new AxSHDocVw.AxWebBrowser();
> ((System.ComponentModel.ISupportInitialize)(this.m _IE)).BeginInit();
> this.SuspendLayout();
> //
> // m_IE
> //
> this.m_IE.Enabled = true;
> this.m_IE.Location = new System.Drawing.Point(0, 0);
> //this.m_IE.OcxState =
> ((System.Windows.Forms.AxHost.State)(resources.Get Object("m_IE.OcxState")));
> this.m_IE.Size = new System.Drawing.Size(804, 580);
> this.m_IE.TabIndex = 7;
> this.m_IE.DocumentComplete += new
> AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent Handler(this.OnDocumentComplete);
> //
> // Html2Image
> //
> this.Controls.AddRange(new System.Windows.Forms.Control[] { this.m_IE});
> this.Size = new System.Drawing.Size(292, 266);
> ((System.ComponentModel.ISupportInitialize)(this.m _IE)).EndInit();
> this.ResumeLayout(false);
> }
> #endregion
>
> //IE InterOp
> #region IHTMLElement2 GetHtmlBody()
> private IHTMLElement2 GetHtmlBody()
> {
> IWebBrowser2 _wb2 = (IWebBrowser2) m_IE.GetOcx();
> Application.DoEvents();
> IHTMLDocument2 _htmlDocument2 = (IHTMLDocument2) _wb2.Document;
> Application.DoEvents();
> return (IHTMLElement2)_htmlDocument2.body;
> }
> #endregion
>
> //Win32 InterOp
> #region extern IntPtr SelectObject()
> [DllImport("Gdi32.dll")]
> private static extern IntPtr SelectObject(
> IntPtr hdc, // handle to DC
> IntPtr hgdiobj // handle to object
> );
> #endregion
> #region extern bool DeleteObject()
> [DllImport("Gdi32.dll")]
> private static extern bool DeleteObject(
> IntPtr hObject // handle to graphic object
> );
> #endregion
> #region extern IntPtr CreateCompatibleDC()
> [DllImport("Gdi32.dll")]
> private static extern IntPtr CreateCompatibleDC(
> IntPtr hdc // handle to DC
> );
> #endregion
> #region extern bool DeleteDC()
> [DllImport("Gdi32.dll")]
> private static extern bool DeleteDC(
> IntPtr hdc // handle to DC
> );
> #endregion
> #region extern bool PrintWindow()
> [DllImport("User32.dll")]
> private static extern bool PrintWindow(
> IntPtr hwnd, // Window to copy
> IntPtr hdcBlt, // HDC to print into
> uint nFlags // Optional flags // must contain
> PW_CLIENTONLY
> );
> #endregion
> #region extern int SendMessage()
> [DllImport("User32.dll")]
> private static extern int SendMessage(
> IntPtr hWnd, // handle to destination window
> uint Msg, // message
> uint wParam, // firstmessage parameter
> uint lParam // second message parameter
> );
> #endregion
> }
> }
>
> "Dave A" <dave@.sigmasolutionsdonotspamme.com.au> wrote in message
> news:eIhiZOF4FHA.3628@.TK2MSFTNGP12.phx.gbl...
>> Sorry - I should have been more clear. I want a thumbnail representation
>> of what the page will actually look like.
>>
>> Regards
>> Dave
>>
>> "Josh Mitts" <joshrm@.msn.com> wrote in message
>> news:eO%235Ps23FHA.3880@.TK2MSFTNGP12.phx.gbl...
>>> Hi Dave,
>>>
>>> If I understand you right, you want to show a preview of the form to
>>> your user, right? How are you rendering the final HTML? Are you using
>>> ASP.NET server controls? Or are you just rendering straight HTML? If you
>>> are just rendering straight HTML, you can update a <div> tag or
>>> <asp:Label> control with your final HTML. You can do this on the
>>> server-side by simply instantiating a HtmlGenericControl for your div
>>> tag and updating its InnerHtml property with your final HTML...i.e.
>>> something like this:
>>>
>>> <div ID="PreviewPanel" runat="server">
>>> </div>
>>>
>>> And in your server code:
>>>
>>> // optional, depending on if you are using ASP.NET 2.0 or not
>>> public HtmlGenericControl PreviewPanel;
>>>
>>> [C#]
>>> string finalHtml = "..."; // set this to your application generates
>>> PreviewPanel.InnerHtml = finalHtml;
>>>
>>> Voila, you are now rendering the HTML on the page. Just make sure to do
>>> this upon every refresh, i.e. after every time your client updates
>>> something on the page.
>>>
>>> If you want to do something more complicated, i.e. render the ASP.NET
>>> server controls, let me know.
>>>
>>> --
>>>
>>> Joshua Mitts
>>> joshrm@.msn.com
>>>
>>>
>>> "Dave A" <dave@.sigmasolutionsdonotspamme.com.au> wrote in message
>>> news:%23YRXaa23FHA.2424@.TK2MSFTNGP10.phx.gbl...
>>>>I am writing an ASP.NET tool that will allow the client to create their
>>>>own online froms. ie the client can add tect boxes, text, drop
>>>>downs,etc with absolutely no technical skill what so ever. The form can
>>>>then be deployed to their intranet.
>>>>
>>>> The form designer is somewhat WYSIWYG but it contains a heap of 'edit',
>>>> 'delete' and reordering buttons that are not seen when the form is
>>>> acutally being used.
>>>>
>>>> I would love to have a preview image of what the form will actually
>>>> look like when it has been rendered in IE and display it in the form
>>>> designer. Much like a the print preview in Word.
>>>>
>>>> I figure that my server would need some component that would acutally
>>>> render the page in some invisible IE and then take a screen shot of the
>>>> web page and then return the image. The designer could then hyperlink
>>>> to that image so the use could see a preview.
>>>>
>>>> Another option would be to have an embedded frame but to adjust its
>>>> 'zoom' to be very small. Unfortunately frames do not support such a
>>>> mythical 'zoom' feature.
>>>>
>>>> Does any one have any idea about how I might solve this problem?
>>>>
>>>> The poor mans option is to have a Preview button in the designer that
>>>> will lauch a new browser window and display the form but I am trying to
>>>> steer away form this.
>>>>
>>>> Regards
>>>> Dave A
>>>>
>>>>
>>>
>>>
>>
>>
Will this work with .Net 2.0 ?
Do any special references need to be added to the project?

--Alex

Server Side Validation

Hello,
I have made a custom control for a text field. I have to do server side validation for it. I just want it to see if a password equals a given value, if not validation should fail.
Can someone provide me with some pseudo script as I am new to ASP.NET.
Thanks.In your custom control, create a public property (read only), "IsValidPassword". In IsValidPassword's get portion, check for whether txtPassword.Text equals your value. If it does, return true, else return false.

So it'd look something like

public bool IsValidPassword
{
get
{
if(txtPassword.Text == "mendhak")
{
return true;
}
else
{
return false;
}
}
}
Thanks for your answer. But some confusion still exists. I have the following code and it complies without error.

protected void validatePass_ServerValidate(object source, ServerValidateEventArgs args)
{
if (txtPass.Text != "Mohit")
{ validatePass.IsValid = false;
validatePass.ErrorMessage = "Wrong Password!";

}
else validatePass.IsValid = true;

}
}

But it does not generate an error message when the wrong password is entered. What do I have to do to get an error message to be generated as is is the case with the CLIENT SIDE controls I have made...

Thanks!
Aah, you could've just continued your questions together in this thread rather than create a new thread for it.

Now, you should use args.IsValid = false rather than the name of the validator itself.
Thank you!

That works

My program works as I want it to but I have a theoretical question. If I want an error message to display when args.IsValid = false, for it to be considered SERVER SIDE do I have to include it in my code as follows:

if (txtPass.Text != "Mohit")
{args.IsValid = false;
validatePass.Text = "*";
validatePass.ErrorMessage = "Wrong Password!";


}
else args.IsValid = true;

I ask since I can set the error message in the custom validator control but I am worried if I do, it will be considered server side. I am not sure hence I ask.
Thank you!

That works

My program works as I want it to but I have a theoretical question. If I want an error message to display when args.IsValid = false, for it to be considered SERVER SIDE do I have to include it in my code as follows:

if (txtPass.Text != "Mohit")
{args.IsValid = false;
validatePass.Text = "*";
validatePass.ErrorMessage = "Wrong Password!";


}
else args.IsValid = true;

I ask since I can set the error message in the custom validator control but I am worried if I do, it will be considered server side. I am not sure hence I ask.
I ask since I can set the error message in the custom validator control but I am worried if I do, it will be considered server side. I am not sure hence I ask.

I meant to say it would be considered CLIENT SIDE...;)
If I understand you correctly, which I probably don't, then you fear the .ErrorMessage property, right?

ErrorMessage and Text are properties of your validator. When you set them, the page will show the error message/text as your page is setup. Now, are you asking whether... actually... I don't understand your question. Try rephrasing it?
If I set up the properties for error message and text in the custom validator instead of setting them up in the function as I did, would my validation still be considered SERVER SIDE VALIDATION?
From a user perspective, yes... because the page posted back and then came back with the error message.

From a programmer's perspective, yes... because it's all in the codebehind.

You don't want it to be serverside validation... why?
I want it to be all server side validation.;)

That is why I was checking. This control is supposed to be server side vaidation only.
In that case, your question's been answered, yes?
Yup!

Thanks!

Saturday, March 24, 2012

Server.Execute against same page hangs ASP.NET

We have a page which sends a copy of itself via email to customers. To
enable this, the page calls Server.Execute on itself into a text stream and
strips its own output down to HTML presentable to the customer.
In our Test environment (but not our DEV or Local envs) we are experience an
ASP.NET lockup. The WHOLE asp.net architecture freezes, and we must reboot
the server before any of our other ASP.NET apps will work.
This is a sample of the code which appears to be the culprit. We commented
out the Server.Execute and substituted some junk text to build sbText and th
e
code worked fine on our test environment again.
-- Locks server
StringBuilder sb = new StringBuilder();
sb.Append(base.AppRoot).Append("/ER/OOWLetter.aspx?ERNumber=");
sb.Append(erNumber);
System.IO.TextWriter textwriter = new System.IO.StringWriter();
StringBuilder sbText = new StringBuilder(textwriter.ToString());
Server.Execute(sb.ToString(), textwriter);
Is there any known issue with Server.Execute on itself?I expect it would just cause a recursive request of the page requesting
server.execute - and hang your server?
Regards
John Timney
Microsoft Regional Director
Microsoft MVP
"Chuck Haeberle" <Chuck Haeberle@.discussions.microsoft.com> wrote in message
news:6F2D019E-2D08-48EC-AC32-0DF6BBDAD3DE@.microsoft.com...
> We have a page which sends a copy of itself via email to customers. To
> enable this, the page calls Server.Execute on itself into a text stream
and
> strips its own output down to HTML presentable to the customer.
> In our Test environment (but not our DEV or Local envs) we are experience
an
> ASP.NET lockup. The WHOLE asp.net architecture freezes, and we must
reboot
> the server before any of our other ASP.NET apps will work.
> This is a sample of the code which appears to be the culprit. We
commented
> out the Server.Execute and substituted some junk text to build sbText and
the
> code worked fine on our test environment again.
> -- Locks server
> StringBuilder sb = new StringBuilder();
> sb.Append(base.AppRoot).Append("/ER/OOWLetter.aspx?ERNumber=");
> sb.Append(erNumber);
> System.IO.TextWriter textwriter = new System.IO.StringWriter();
> StringBuilder sbText = new StringBuilder(textwriter.ToString());
> Server.Execute(sb.ToString(), textwriter);
> Is there any known issue with Server.Execute on itself?
It shouldn't, but I'll look into it.
The call to Server.Execute occurs only within a postback when a button on
the page is pushed to generate the email. As I said, this poses no problem
whatsoever on our local machines (5 developers) or on our development server
environment. Only in our Test env is there an issue.
"John Timney (Microsoft MVP)" wrote:

> I expect it would just cause a recursive request of the page requesting
> server.execute - and hang your server?
> --
> Regards
> John Timney
> Microsoft Regional Director
> Microsoft MVP
>
> "Chuck Haeberle" <Chuck Haeberle@.discussions.microsoft.com> wrote in messa
ge
> news:6F2D019E-2D08-48EC-AC32-0DF6BBDAD3DE@.microsoft.com...
> and
> an
> reboot
> commented
> the
>
>

Server.Execute against same page hangs ASP.NET

We have a page which sends a copy of itself via email to customers. To
enable this, the page calls Server.Execute on itself into a text stream and
strips its own output down to HTML presentable to the customer.

In our Test environment (but not our DEV or Local envs) we are experience an
ASP.NET lockup. The WHOLE asp.net architecture freezes, and we must reboot
the server before any of our other ASP.NET apps will work.

This is a sample of the code which appears to be the culprit. We commented
out the Server.Execute and substituted some junk text to build sbText and the
code worked fine on our test environment again.

-- Locks server
StringBuilder sb = new StringBuilder();
sb.Append(base.AppRoot).Append("/ER/OOWLetter.aspx?ERNumber=");
sb.Append(erNumber);
System.IO.TextWriter textwriter = new System.IO.StringWriter();
StringBuilder sbText = new StringBuilder(textwriter.ToString());
Server.Execute(sb.ToString(), textwriter);

Is there any known issue with Server.Execute on itself?I expect it would just cause a recursive request of the page requesting
server.execute - and hang your server?

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP

"Chuck Haeberle" <Chuck Haeberle@.discussions.microsoft.com> wrote in message
news:6F2D019E-2D08-48EC-AC32-0DF6BBDAD3DE@.microsoft.com...
> We have a page which sends a copy of itself via email to customers. To
> enable this, the page calls Server.Execute on itself into a text stream
and
> strips its own output down to HTML presentable to the customer.
> In our Test environment (but not our DEV or Local envs) we are experience
an
> ASP.NET lockup. The WHOLE asp.net architecture freezes, and we must
reboot
> the server before any of our other ASP.NET apps will work.
> This is a sample of the code which appears to be the culprit. We
commented
> out the Server.Execute and substituted some junk text to build sbText and
the
> code worked fine on our test environment again.
> -- Locks server
> StringBuilder sb = new StringBuilder();
> sb.Append(base.AppRoot).Append("/ER/OOWLetter.aspx?ERNumber=");
> sb.Append(erNumber);
> System.IO.TextWriter textwriter = new System.IO.StringWriter();
> StringBuilder sbText = new StringBuilder(textwriter.ToString());
> Server.Execute(sb.ToString(), textwriter);
> Is there any known issue with Server.Execute on itself?
It shouldn't, but I'll look into it.

The call to Server.Execute occurs only within a postback when a button on
the page is pushed to generate the email. As I said, this poses no problem
whatsoever on our local machines (5 developers) or on our development server
environment. Only in our Test env is there an issue.

"John Timney (Microsoft MVP)" wrote:

> I expect it would just cause a recursive request of the page requesting
> server.execute - and hang your server?
> --
> Regards
> John Timney
> Microsoft Regional Director
> Microsoft MVP
>
> "Chuck Haeberle" <Chuck Haeberle@.discussions.microsoft.com> wrote in message
> news:6F2D019E-2D08-48EC-AC32-0DF6BBDAD3DE@.microsoft.com...
> > We have a page which sends a copy of itself via email to customers. To
> > enable this, the page calls Server.Execute on itself into a text stream
> and
> > strips its own output down to HTML presentable to the customer.
> > In our Test environment (but not our DEV or Local envs) we are experience
> an
> > ASP.NET lockup. The WHOLE asp.net architecture freezes, and we must
> reboot
> > the server before any of our other ASP.NET apps will work.
> > This is a sample of the code which appears to be the culprit. We
> commented
> > out the Server.Execute and substituted some junk text to build sbText and
> the
> > code worked fine on our test environment again.
> > -- Locks server
> > StringBuilder sb = new StringBuilder();
> > sb.Append(base.AppRoot).Append("/ER/OOWLetter.aspx?ERNumber=");
> > sb.Append(erNumber);
> > System.IO.TextWriter textwriter = new System.IO.StringWriter();
> > StringBuilder sbText = new StringBuilder(textwriter.ToString());
> > Server.Execute(sb.ToString(), textwriter);
> > Is there any known issue with Server.Execute on itself?
>

Thursday, March 22, 2012

server.htmlencode method

hi to all,

As we know that the server.htmlencode method makes html encodeing so what i understand hat if i have a text like that <b>Test string</b>

then when i apply the server.htmlencode method on that text then the output will be :

<b>Test String</b>

and the output after applying this method will be displayed on a Web browser as:

<b>Test string</b>

so my question why we directly send the text <b>Test string</b> to the web browser without using the server.htmlencode method to make encoding?

so ineed some clarification on that topic.

your help is highly appreciated

Best regards

wissam1:

why we directly send the text <b>Test string</b> to the web browser without using the server.htmlencode method to make encoding?

If you do not encode, it will behave as markup (you would see a bolden string in your sample), with all security concerns eventually involved. If instead you do encode, it will render as a plain string.

That's all i guess.

HTH. -LV


HI

HtmlEncoding is done mostly to avoid XSS (Cross Site Scripting) attacks.
Google for more on that.!

Thanks

Server.HtmlEncode(createText.Text) vs. HttpUtility.HtmlEncode(createText.Text);

What is the difference? and which one should I use?

Server.HtmlEncode(createText.Text)

vs.

HttpUtility.HtmlEncode(createText.Text)

Server.HtmlEncode calls HttpUtility.HtmlEncode.


According toReflector, Server is an instance ofHttpServerUtility

Public ReadOnly Property Server As HttpServerUtility
Get
If (Me._server Is Nothing) Then
Me._server = New HttpServerUtility(Me)
End If
Return Me._server
End Get
End Property

And as noted HttpServerUtility.HtmlEncode makes a straight call to the shared method HttpUtility.HtmlEncode

Public Sub HtmlEncode(ByVal s As String, ByVal output As TextWriter)
HttpUtility.HtmlEncode(s, output)
End Sub

So for best performance, you could call directly to HttpUtility.HtmlEncode yourself.

Server.HtmlEncode(createText.Text) vs. HttpUtility.HtmlEncode(createText.Text)

Server.HtmlEncode(createText.Text) vs. HttpUtility.HtmlEncode(createText.Text);

From thedocumentation:

Server.HtmlEncode is a convenient way to access theSystem.Web.HttpUtility.HtmlEncode method at run time from an ASP.NET Web application. Internally,HtmlEncode usesSystem.Web.HttpUtility.HtmlEncode to encode strings.

Tuesday, March 13, 2012

server.mappath error

I am trying to use server.mappath to update a text file on another network drive on the same network as the server the application is running on. Security shouldn't be a problem but I am getting an error. Hereis my Code
 Dim FILENAME As String = server.MapPath("http://appl-08/TB/Test/test.txt")
Dim objStreamWriter As StreamWriter
objStreamWriter = File.CreateText(FILENAME )
objStreamWriter.WriteLine("Note form user")
objStreamWriter.WriteLine(txttext.Text)

I have also tried just mapPath("address"), mapPath ("\\appl-08\wwwroot\TB\test\test.txt")
This is the error I always get!!
Invalid path for MapPath 'http://appl-08/TB/Test/test.txt'. A virtual path is expected.

ANyone got any suggestions.Server.MapPath("TB/Test/test.txt") - assuming the file your working on is in the "appl-08" server root directory directory

If it's in the TB directory then "Test/test.txt"
this is the problem I am working on server appl-07 I need to store the file on appl-08
In which case i would imagine that you have a security issue anyway as you will need to give the ASP account on appl-07 permission to access the folder on appl-08

and then it should be somethign like CreateText("//appl-08/test/test.txt")

I think thats it anyhow i've tried to recreate it on our corporate network to find out for sure but our security settings are too strict for me to do that. It does however find the folder - it just doesn't give me permission to do anything with it.
Ok I can get it to work going to our sql server but not our .net server.
On both servers I created a folder gave it the same permmisions and on the .net server I get the error that I am using the wrong user name or password.
Is there some program that can't be installed or has to be installed for it to work.
perhaps using the .Net account of one machine to access another machine with it's own .Net account is conflicting it?
I dont' know to be honest - Hopefully someone else can help on that one