C# - WebBrowser.DrawtoBitmap() Generating Blank Images For Few Sites Consistently
Mar 18, 2011
I've been using WebBrowser.DrawtoBitmap() in my asp.net page running in separate STA thread to capture web pages as an image. But I found that I'm getting blank images for few sites consistently. I'm aware that the method is not 'officially' supported but it would be nice if someone can provide me any reason or a work around for these blank images issue.
I have a GridView with three Button columns that are set up with images. When I select my path for the image, using the GUI tool that VS provides, the resulting path is something like ~/Images/myicon.png and the image displays fine (sometimes) in the VS Design mode. But the images do not display on the running version of the website (using Firefox) because the image locations resolve to ../Images/myicon.png. I can manually change it to Images/myicon.png and it works fine on the website but then not in VS. How do I get them to behave the same way? These file paths are driving me nuts!
I am using Linq to create a schedule, which includes columns for creation date, modified date, isSubmited, UserId. Anytime that the schedule is created, I would like to automatically add rows to the ScheduleDays table, which has columns for scheduleId, date, etc.
Currently, I am trying to extend the OnValidate method as follows:
Partial Public Class Schedule Private Sub OnValidate(ByVal action As System.Data.Linq.ChangeAction) Dim day As New ScheduleDay[code]....
This code does not work. Rather, I do not even think that it is getting executed. And if it is, it is not adding the scheduleDays to the database, with their specified values. I get no error message, or anything.Is there a better method to extend, instead of OnValidate? Since, there could still be errors with the Schedule being created. Also, is there anything else in my code that is preventing it from running?
I'm currently running a site of a dedicated server but want to scale up using Microsofts Azure cloud platform in the future but im unsure if a certin part of my code will work on azure.The site consists of a gallery of items with an image for each item.The images are stored in a sqlserver database.
I have created a http handler that caches the images to disk and redirects the request to the image (as shown at the end of the post).The images are saved into a virtual directory called "imagecache" inside my ASP.NET application. (i.e. ~/imagecache/ ).
As the web app will run in many virtual machine instances on the Azure platform the images will need to be shared between the instances right?So my question really is.. What is the best way of achieving what I already have on that is compatible wit azure?Image gen code..
public class getimage : IHttpHandler { private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public void ProcessRequest (HttpContext context) { [code]....
i cant access crysrtal report after deployment in IIS i have depolyed my website the pages where my crystal report is just blank .. how can i access crystal reports????
I need to generate small images for certain parts of text. Those will have to fit into the text seamlessly. I know I can not make up for every browser font settings available, but how do I have to check for Linux, Mac and Windows users depending on the user agent? I want to use the right font (of the three "Verdana, Arial, Helvetiva") for the right user agent OS.
So:How do I check for the OS? What do I have to compare to in the user agentWhere can I get the other two fonts. Does the Windows-included Verdana look the same as the one used on Linux (or, is it free anyway? I don't know much about fonts)? Where do I get Helvetica? Is it Mac OS licensed?
Any code examples can be in either c# or VB.NET. I can read both.
I am interested in developing Web Parts that can be used in our ASP.NET sites and our SharePoint sites. An example Web Part I have in mind is a Post Code (Zip Code) look up.- Visual Studio 2010 Premium- SharePoint Designer 2007- Windows 2003 Server (therefore WSS 3.0)- No SharePoint Server
I have a session state that myself and others on my team have been bashing our heads against the wall for the past week. We have tracked it down to the following:
1) Frame page containing content pages creates a session
2) Content page creates a session, stores data in the session
3) User changes drop down list with SelectedIndexChanged autopost back and displayed fields are changed using an UpdatePanel. A new session is created, data stored in the prev. session is lost 4) User posts back, no session is created this time, however the post back fails because the session from step 2 is lost.
Now, a user closes the page, comes back, and it actually starts to work:
1) Frame page containing content page opens (no new session)
2) Content page loads data, stores in session (no new session)
3) User changes drop down list with SelectedIndexChanged auto postback and displayed fields are changed using an UpdatePanel. Sesson NOT lost
4) User posts back form, success
ASP.NET on the first visit to the site insists on creating 3 sessions, we log it in Session_Start. I can't think of any reason this should happen. I've been told the frame will always be on a seperate session; thats fine, its only being used to setup scrolling within a frame in Dynamics CRM. The biggest question is why when we insert data into the session in step #2, it is discarded in step #3.... but only during the first visit to the page!
I've never seen this session behavior before; we don't have any session abandonments in our code, and we never clear session objects, so there shouldn't be any reason for the session to be lost.
I'm using the built-in ASP validators on a few form elements. They work fine - if I click the submit button (a Button), validation occurs without postback and errors are displayed in a ValidationSummary. When that occurs, I also want to call a method in codebehind which changes the CSS of elements, switching their background color to red to reflect errors. I've tried to call this method using both OnClick and OnClientClick in the submit Button, but neither parameter seems to fire the method - client-side validation always takes priority, and a postback never occurs. Can anyone enlighten me?
EDIT #1 Using orandovs link worked alright for changing the element itself, but how about its parent? For example, in C# I'm doing:
foreach (BaseValidator validator in Page.Validators) { Panel panel = validator.Parent as Panel; if (!validator.IsValid) panel.CssClass = "error"; else panel.CssClass = "normal"; }
Is there a way to get the parent control (which are all consistently Panels, so I know CssClass will exist) using JavaScript? Something like: $("#" + Page_Validators[i].controltovalidate.parent).CssClass("error");
I can't display some controls in the webbrowser such as MultiView, Menu, SiteMapPath or TreeView, is only white screen.
Other controls work. And some controls properties are restricted, I haven't full options. Before I used Visual Studio 2008 and I had less problems than now, I have VS 2010.
I tried to use the WebBrowser control in an ASP .NET application:
public BrowserForm() { webBrowser1 = new WebBrowser(); webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
[Code]....
But still it's not working for me as desired...giving me weired errors like:
Error HRESULT E_FAIL has been returned from a call to a COM component
I'm not an expert of threading or COM but trying to convert a WindowApplication to WebApplication which takes a screenshot of a web page provided a URL. :(
HOW TO Force C#/ASP.NET to not rename input elements to work consistantly with Form.GetValues.
ASP.NET changes the "name" property of input elements set with "runat=server" to match their ID property at run time. This causes server-side calls to HttpRequest_Page.Form.GetValues to now be able to get the expected Form element.
The reason why this fails is because ASP.NET changes the "name" properties of these controls to match their "ID". Thus at run time they become as such:
I do not want ASP.NET doing this. I do not want to change the naming convention of my id properties either. In fact, I need the ID to be different than the name, as I use client side script to change/create/delete controls on the fly.
I found a C# web application that fetchs a thumbnail image of a webpage. It works well, only my site is in vb.net. I used a conversion tool. Windows FORMs doesn't fly, and I get an error. Is there something I can import to get the Webbrowser() to work in my application ? Dim m_Webbrowser as NEW Webrowser is underlined in blue. Also, I have noticed that when I select Show All in my toolobox, alot of tools are greyed out. Specifically under common tools, the webbrowser control is greyed out for a web application but they are available for a project. I want to have a webbrowser control in my website application. (vb.net)Most of the following is also underlined in blue:
I have a form which a user can fill in x times with the data they want too. The form is posted to the following Action.
[HttpPost] public ActionResult Manage(ProductOptionModel DataToAdd) { if (!ModelState.IsValid) { return View(DataToAdd); } var ProdServ = new ProductService(); if (DataToAdd.ID != 0) { //Edit Mode. DataToAdd = ProdServ.EditProductOption(DataToAdd); ViewData["Message"] = "Option Changes Made"; }else { //Add DataToAdd = ProdServ.AddProductOption(DataToAdd); ViewData["Message"] = "New Option Added"; } var RetModel = new ProductOptionModel() {ProductID = DataToAdd.ProductID}; return View(RetModel); }
So at the bottom I blank the model (Leaving just the required field) and then return to the view. However the view holds the data from the previously submitted form. I have debugged the code and checked that the RetModel variable is empty.
In my windows application I'm loading more than 100 urls in my web browser control one by one in a for loop and need to print them programatically after each URL gets loaded . But, I keep getting the Javascript error for so many URLs. I'm not sure why this error keep coming.
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" [URL] 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(); }...................................
A requirement of a program I am making is that it can 'print' a given URL into a PDF - the server has a PDF printer installed (and is the default printer), so it's just a matter of printing the page programmaticly, and it seems the best way is to use the WebBrowser control - however, I am running into issues
[Code]....
With the above code, I get a script error 'dialogArguments.___IE_PrintType' is null or not an object' in shdoclc.dll/preview.dlg. If I have wb.Print() to somethign like wb.ShowSaveDialog() (or something like that, can't remember exactly), I notice the 'wb' object's document is a blank page, with just <html> tags and named 'about:blank'. But strangely, almost identical code (without the threading bit in the page_load method) works perfect in a normal Winforms based application.
I want to authenticate to linkedIn website and scrape the content in asp.net. In windows application we use windows brwoser control. Is there any anlternate in web application ?
I've been trying to get image caching working for the last 8 hours and I keep the same problem time and time again, I'm trying to cache Images at the moment and then when thats succesful, apply this to cache my js and css files. I have at the moment Sql Dependancy caching working on my dynamic pages but the page still takes to long due to images not caching.
What I have tried is going to IIS7 Management and adding HTTP Response Header for the images folder and setting various things for the cache control.i dont care how long it caches it on the client or on the proxy servers i just would like it to check when the file was modified and compare it with the one in the client or proxy cache and if they are different then fetch the new image which has been ftp up. i could solve this by changing the image name but the thing is the image name is generated when they are ftp'd to the site by an application and the name is a direct reference to the product so i cant change the name each time, as it would mean making a lot of otherpages accross the board.
so What i would like, is to set and expiry date of lets say 32 days or more on the images and then check to see if they have changed by date modified or some other way of checking(Etags maybe) I'm not sure, if they have changed on the server then redownload and recache them, I tried using post-check and pre-check together but that just permantly cached them, so when i change the image the only way it would display the new image is to just hit F5.
In Brief, how can i Cache images, on the client machine/ proxy cache and recache them when the modified date of the file has changed.
I want to show on one of my pages a slideshow type page. Basically I want it to show a selection of images from a folder and have the images scroll from right to left.
I want to write one program by visual studio 2008 (C# and ASP) that has web application and windows application.
I want to get clients images in web app(upload) and store them in DB (mysql) then send these images to windows app via web service (so i new web service, not web site). But i have 2 problems:
I have 2 ways to store images in mysql, first i should have BLOB field in DB -that it takes more space-, second i should save just name of each image in DB(so have image in one folder) -in this way i don't know how get image from clients and store them in that folder-. which one? Or what other? How (code) can i transfer image via web service(Byte[] or? ).
how to upload images to server(application/images folder) and retrive(display) from and on client PC for asp.net. its just for uplaoding logo directly to server folder and retriving from server to client. i am not getting server path on client pc for image.
i have the following scenario, i have a column of a gridview that shows me a text telling me is the user is allowed or not to access to some page, but now i just showing allow and deny, but i wanna show images that represent me the action, how can i do that?