Hi everyone,
Yeah some people would say "Are you crazy using winforms controls inside asp forms"... and I think they are right. But I would say.. "I'm not the only one!!, take a look"
So...
Doing some kind of stuff like the previous link. I did the following:
using System; using System.Threading; using System.Windows.Forms;
namespace XXXX.aspx.Print { public partial class Drucker : System.Web.UI.Page { private ManualResetEvent mre = new ManualResetEvent(false);
protected void Page_Load(object sender, EventArgs e)
{
Threading();
}
private void Threading()
{
Thread t = new Thread(new ThreadStart(GoAhead));
t.SetApartmentState(ApartmentState.STA);
t.Start();
mre.WaitOne();
t.Abort();
}
private void GoAhead()
{
DateTime time = DateTime.Now;
WebBrowser webBrowser = new WebBrowser();
webBrowser.Navigate(Request.UrlReferrer.ToString());
webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted);
while (true)
{
Thread.Sleep(0);
TimeSpan elapsedTime = DateTime.Now - time;
if (elapsedTime.Seconds >= 13)
{
mre.Set();
}
System.Windows.Forms.Application.DoEvents();
}
}
void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser webBrowser = (WebBrowser)sender;
if (e.Url.AbsolutePath != webBrowser.Url.AbsolutePath) return;
webBrowser.Print();
}
}
}
Now...
the DocumentCompleted event is not fired (neither ProgressChanged) and I've tried the next:
- Add the library MsHtml.dll to my project and place the file into my lib folder... I did it... No changes.
- Try to handle the state of the WebBrowser.ReadyState... I did it... No changes (Actually after receive the WebBrowserReadyState.Complete I tried to print the document with webBrowser.Print(); but I receive a weird IE pop up telling me: "'dialogArguments.__IE_PrintType' is Null or a not an object'"... ok so doing some research I got: a microsoft topic about dcomcnfg and some com security settings I did it... No changes. ...
By the way I´m working in 64bits, Win7... So before I format the whole computer... Any suggestions?