how can you use mshtml DOM object to grab rendered asp.net page?

R

Randall Arnold

I know how to use MSHTML to grab the innerhtml from an html web page, but
what if I want to look at elements of a rendered aspx page? Is there any
way to do this using the MSHTML DOM object?

Thanks,

Randall Arnold
 
R

Randall Arnold

Thanks Robbe. C# makes this VB developer's head spin, and I'm obviously out
of my league based on what I've perused so far, but I'll see if I can get
anything useable out of your well-written article.

I thought this was going to be simple when I started... hoo boy... : (

Randall
 
J

Jim Cheshire

R

Randall Arnold

Um, but what about this comment (from the link):

"The problem is that the response's output stream is write-only, presumably
for performance reasons. Any attempt to read the output stream fails"

Basically, I want to grab a table rendered by the asp.net code and copy it
to the clipboard. So far all suggested methods have failed. I'm sure what
I want to do *HAS* to be possible... just can't find out how...

Randall
 
J

Jim Cheshire

Randall said:
Um, but what about this comment (from the link):

"The problem is that the response's output stream is write-only,
presumably for performance reasons. Any attempt to read the output
stream fails"


That comment applies to the PreSendRequestContent and not to a response
filter.

Basically, I want to grab a table rendered by the asp.net code and
copy it to the clipboard. So far all suggested methods have failed. I'm
sure what I want to do *HAS* to be possible... just can't find
out how...

I would seriously reconsider that desire. What is it that you are trying to
accomplish?

--
Jim Cheshire
================================
Blog: http://blogs.msdn.com/jamesche

Latest entry: Digging into Objects
Describes the details of digging into
memory usage with the debugger.
 
R

Randall Arnold

This is the gist of it: our organization currently uses a VB6 program to
track and report quality issues. The developer is long gone and I have no
access to current source code.

I've been tasked to develop a new solution and the preference is web-based.
To that extent, I selected asp.net based on my experience with vb and
vb.net.

Users will view tables and charts on the intranet site and need to have the
ability to publish them in other applications (Word, Powerpoint, Publisher,
et al). I can easily copy the charts to any app because the chart object
has a method that creates bitmaps or metafiles on the fly, and even though
I'd rather copy the actual chart object, this will suffice.

The problem arises with copying tabular info. I've exhausted numerous ideas
and not one single one has worked unless it involves saving the table to an
html file, loading it in Word, copying the resulting table to the clipboard,
and pasting it. That's just plain nuts IMO. I can't understand why I can't
simply programmatically access the rendered html table, especially since I
can highlight it with a mouse, copy, paste and done. I should be able to
emulate that action in vb.net code, right? If I can't *I* have serious
reservations about the maturity level of asp.net.

Randall
 
J

Jim Cheshire

Randall said:
I can't understand why I can't simply programmatically
access the rendered html table, especially since I can highlight it
with a mouse, copy, paste and done. I should be able to emulate that
action in vb.net code, right? If I can't *I* have serious
reservations about the maturity level of asp.net.
Randall

I went back and read your original post. It seems that you want to copy this
to the client clipboard. Is that correct? If so, can't be done in ASP.NET.
ASP.NET code doesn't execute on the client.

--
Jim Cheshire
================================
Blog: http://blogs.msdn.com/jamesche

Latest entry: Digging into Objects
Describes the details of digging into
memory usage with the debugger.
 
R

Randall Arnold

Ok, I can understand that, but with all due respect I still can't accept
that I can't achieve this one way or another. Again, I have no problem
copying the chart graphic to the clipboard and bringing it into PowerPoint
with 2 simple lines of code, and it looks beautiful. I have to believe that
there is *some* way of copying a simple table over as well, without going
through contortions. I keep seeing hints that it can be done but either the
methods don't work for me or there aren't enough details provided. Someone
told me there's a way to stream the table to PowerPoint but provided no
other info. ???

Right now the 2 options I know I can use are the cumbersome html file
generation technique and building each and every table from scratch in
PowerPoint using vba with the interop. I have issues with either approach,
but I'll use the former if I have no other choice. MUCH less code.

The thing that gets me is I found an asp.net/JavaScript combo trick that
allows the user to toggle a table between hidden and visible. I got this to
work on the page in question. If I can do THAT, I have to believe I can use
a similar trick to copy the table. I just need to know the method.

Randall Arnold
 
J

Jim Cheshire

Randall said:
The thing that gets me is I found an asp.net/JavaScript combo trick
that allows the user to toggle a table between hidden and visible. I
got this to work on the page in question. If I can do THAT, I have
to believe I can use a similar trick to copy the table. I just need
to know the method.

This is not an ASP.NET question. It is a question concerning client-script.
A quick Google search on "javascript clipboard" reveals thousands of hits.

I have to say as well that if you don't get your head around the fact that
ASP.NET is server side code with no connection to the client, you're going
to be quite confused as your development continues. This is the basic
foundation of ASP.NET and it's something that every ASP.NET absolutely must
know.

--
Jim Cheshire
================================
Blog: http://blogs.msdn.com/jamesche

Latest entry: Digging into Objects
Describes the details of digging into
memory usage with the debugger.
 
R

Robbe Morris [C# MVP]

Is there a reason you don't have set aside classes with public methods
to generate your charts, html tables, and other output mechanisms?

You could then wire up a few .NET Web Services to call these
specific methods from other parts of your web application or
even in VBA in Office applications.

It appears that you've put a bunch of this logic in your code
behind files. While this doesn't prohibit you from parsing
out particular pieces of info from the page, it does make
it more problematic.

You should refactor your asp.net pages and put the methods
to draw your html tables, charts, etc. in separate classes and
perhaps even in their own assembly.

This way, you can call the methods via web services and not have to bother
parsing anything. And, it would be easy to use the XmlHttp
object from the MSXML4 (or whatever the latest version is)
to call your web service via a macro in office. Now, you can call
the same method easily from external applications as well
as your asp.net application.

I think you've just architected yourself into a bad corner knowing
that you want to share output from your asp.net app to other
applications. You may want to review the following.
It will help you avoid these types of things in the future.

http://www.eggheadcafe.com/articles/aspnet_how_to_create_object_oriented_applications.asp

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.eggheadcafe.com/forums/merit.asp
 
R

Randall Arnold

I understand that asp.net is server side.

What I am trying to say is that my overall solution is asp.net, but I am not
above implementing other technologies that can also work on an asp.net page
*client side*. To that extent, I spent 2 days exploring the JavaScript
clipboard links Google turned up. Not a single code example I tried worked
for my situation. The biggest problem is that they were all about copying
text; I want to copy a table object. Couldn't get that to work.

However, note that, as I said, copying the chart control contents (as a
bitmap) *works from the server side*. Obviously the clipboard CAN be
accessed; it is just not 100% functional, i.e., objects cannot be copied. I
am told this is a security issue. Since my application is strictly
intranet, I find this absurd, but that's another battle.

I have resigned myself to using Word as a table-rendering engine. It's
clunky, but it works.

Randall
 
R

Randall Arnold

I am very new to asp.net/vb.net (although over 10 years with vb), and what
you describe is utterly foreign to me. If I knew what all that was, trust
me: I'd probably have done it.

Looks like I have a lot more to learn... and based on the poor luck I'm
having in searches, I don't even know where to start. No books, it seems,
geared toward what I am trying to do.

And FYI, it was never my intention to design myself into a corner: I had a
mandate to modernize a VB6 app and provide it with various publishing
(export) options, assumed asp.net was the way to go, and have now come to
the conclusion asp.net is far too immature, restrictive and poorly supported
despite the hype from Microsoft. IMO, I should not have to jump through
hoops or worry about security restrictions when my environment is 100%
intranet.

Randall
 
J

Jim Cheshire

Randall said:
And FYI, it was never my intention to design myself into a corner: I
had a mandate to modernize a VB6 app and provide it with various
publishing (export) options, assumed asp.net was the way to go, and
have now come to the conclusion asp.net is far too immature,
restrictive and poorly supported despite the hype from Microsoft. IMO, I
should not have to jump through hoops or worry about security
restrictions when my environment is 100% intranet.

Randall,

I think your problem is that you have undertaken a project that requires you
to have an understanding of HTTP applications and the restrictions imposed
on them, and because your experience is not in this area, you are becoming
frustrated. That happens to plenty of people. While it might be tempting to
blame the technology, I think doing so in this case is a mistake.

Yours is an issue that doesn't lend itself to resolution on a newsgroup
because your knowledge of the technology involved is limited. The best
recommendation one could give you is to purchase a book on ASP.NET (Dino
Esposito's books are excellent) and learn what you need to know to
competently develop this application. As you head down that road, I'm sure
that people here will be glad to help you.

--
Jim Cheshire
================================
Blog: http://blogs.msdn.com/jamesche

Latest entry:
Getting the PID and TID of a COM Call

Describes how to get the PID of the
dllhost process a COM call is executing
in and how to locate the thread as well.
 
R

Randall Arnold

It isn't an absolute lack of understanding, Jim. I wrote apps in VB6 that
used the webbrowser control to work all sorts of magic. I've designed web
pages that had to perform all kinds of tricks (based on customer requests)
and for a while I was adept at javascript just out of necessity (have since
forgotten most of it due to lack of use).

I understand HTML. I understand VB. I even understand ASP 2.0. I'm just
having problems with asp.net.

And while my lack of familiarity with asp.net is certainly a hindrance, it
isn't just that. There really ARE functional problems here. Again, the
asp.net security model seems to automatically assume Internet deployment,
and that cripples my 100% intranet solution. IMO this is a flaw in
Microsoft's philosphy. I believe a developer should be able to inform the
IDE that he is coding for a purely intranet environ and thus be rewarded
with expanded capabilities; conversely, I agree with the decision to lock
down many aspects of Internet apps.

Note that I can't even get IIS to run an aspx web page on my laptop, and
Microsoft's KB solution to this known issue did not work. Neither has ANY
recommended solution. That's just one of many, many frustrations
encountered.

I *am* understanding more and more, though, and very quickly. The more I
understand, however, the more disillusioned I become-- mainly due to the
restrictions mentioned above or the very poor (and often conflicting)
documentation I have encountered. As for asp.net books, I have several,
including Dino's, and not one has been any help whatsoever for the
application in question. I would dearly love to see a book that
specifically addressed developing and deploying 100% intranet solutions
using asp.net/vb.net. I'd pay good money for such a thing... but I'm not
holding my breath. I'm utterly amazed at the dearth of info on this
subject. The technology *should* lend itself very well to corporate
intranets but it seems MS has relegated that use to the backburner...

Randall Arnold
 
J

Jim Cheshire

Randall said:
It isn't an absolute lack of understanding, Jim. I wrote apps in VB6
that used the webbrowser control to work all sorts of magic. I've
designed web pages that had to perform all kinds of tricks (based on
customer requests) and for a while I was adept at javascript just out
of necessity (have since forgotten most of it due to lack of use).

I would dearly love to
see a book that specifically addressed developing and deploying 100%
intranet solutions using asp.net/vb.net. I'd pay good money for such
a thing... but I'm not holding my breath. I'm utterly amazed at the
dearth of info on this subject. The technology *should* lend itself
very well to corporate intranets but it seems MS has relegated that
use to the backburner...

Understood, but understand that working with the Webbrowser control is
nothing like developing an ASP.NET application. ;)

We certainly haven't ignored ASP.NET as an Intranet development tool. Many
of the companies I work with are developing Intranet applications and all of
our internal Web applications (and we use a TON of them) are ASP.NET apps
purely because it is so well suited to that type of environment.

Perhaps you can go into a bit more detail as to what makes you feel that
ASP.NET doesn't lend itself well to Intranets and we can help with that
specifically.

--
Jim Cheshire
================================
Blog: http://blogs.msdn.com/jamesche

Latest entry:
Getting the PID and TID of a COM Call

Describes how to get the PID of the
dllhost process a COM call is executing
in and how to locate the thread as well.
 
R

Randall Arnold

In general, my problem is that right off the bat I run into security
obstacles. I mentioned one, the inability to use IIS on my laptop to run an
aspx page. Searching on the subject led me to suggestions involving batch
files running CACL commands. Not a single CACL call I executed was
successful. Sigh. The suggestion to add a new user to machine.config
failed because the server didn't recognize the recommended username value.
Other recommendations all involve registry hacks, text file editing, etc etc
etc-- all very crude solutions IMO and not one tried has worked. So,
specifically, I still cannot execute aspx files on my development pc using
IIS.

I've already belabored the clipboard dilemma that has cost me countless
hours of deadend trial and error. I have a solution now that works, but I'm
still disgusted that there's no clean way to do what I wanted and that I had
to resort to a kludge that uses Word as a table-copying engine. Which
brings up another gripe: THAT solution won't run from my server. The error
is that Word can't be started. I assume this means Word needs to be
installed on the server (I had assumed the interop would create the instance
on the client machine-- oops). But I guarantee you the IT guys I have to
deal with on this will nix that. So now my solution is kaput. Back to
square 1: I still cannot copy a simple html table from a web page to a
Powerpoint application, a feature my application MUST have. That confounds
and astounds me.

These are just two examples of many. So far it's my experience that every
single hurdle I hit has Security as the crippling culprit. "Oh no," one MVP
tells me, "you NEVER want the clipboard to copy OBJECTS from web pages!"
Sure I do. I'm in an intranet. I'm not worried about malicious use. It's
not a factor. So why can't I have this capability, out of the box, in my
intranet app? I can copy bitmaps to the clipboard. I can copy raw text.
Just not a table. $%$%$@!

I understand the need for heightened security, and don't fault MS for
implementing it-- especially given the beating over publicized IE holes
(last week's big one to wit). But I also feel I should be able to pry the
hood open a little wider in an intranet.

Sorry to beat this dead horse-- but I have a project upon which key managers
have pinned high expectations and it's frustrating to me to hit so many
walls over what I had presumed to be minor details. I can create this app
in VB6. I can even create it in vb.net winforms. But for various reasons I
prefer asp.net webforms. And I hate having to call it quits, but it sure
looks like I'll have to. A shame. I was really excited at what I thought
asp.net could do.

Randall Arnold
 
J

Jim Cheshire

Randall said:
In general, my problem is that right off the bat I run into security
obstacles. I mentioned one, the inability to use IIS on my laptop to
run an aspx page. Searching on the subject led me to suggestions
involving batch files running CACL commands. Not a single CACL call
I executed was successful. Sigh. The suggestion to add a new user
to machine.config failed because the server didn't recognize the
recommended username value. Other recommendations all involve
registry hacks, text file editing, etc etc etc-- all very crude
solutions IMO and not one tried has worked. So, specifically, I
still cannot execute aspx files on my development pc using IIS.


First of all, you don't need to run CACLS to run ASP.NET pages. What
problems were you having?

If you do have a need to run CACLS from a Web page, we have plenty of people
doing this and it will work. However, once again, you have to understand the
architecture. You must make sure that you do one of two things:

1. Either run the worker process under a privileged user who can run CACLS.
(Not recommended, Intranet or not.)
2. Impersonate a privileged user who can run CACLS.

Number 2 is the strong recommendation, and in this type of scenario, it
would be strongly advisable to use code-level impersonation.


I've already belabored the clipboard dilemma that has cost me
countless hours of deadend trial and error. I have a solution now
that works, but I'm still disgusted that there's no clean way to do
what I wanted and that I had to resort to a kludge that uses Word as
a table-copying engine. Which brings up another gripe: THAT solution
won't run from my server. The error is that Word can't be started. I
assume this means Word needs to be installed on the server (I had
assumed the interop would create the instance on the client machine--
oops). But I guarantee you the IT guys I have to deal with on this
will nix that. So now my solution is kaput. Back to square 1: I
still cannot copy a simple html table from a web page to a Powerpoint
application, a feature my application MUST have. That confounds and
astounds me.


Once again, this is an architectural issue. Office applications are not
designed to be run non-interactively. When they load up, they load up
user-specific settings from the profile. When you are running your ASP.NET
app, the worker process is running under the context of a non-interactive
user and automation of Office applications is not supported.

Even if you can get it to work, doing it would be highly inadvisable due to
resource problems that would likely be encountered. This is not an
architectural flaw. It simply has to do with the fact that Windows
applications are designed to be run by the one person logged into the
console and not by a large number of users accessing a Web application.


Sorry to beat this dead horse-- but I have a project upon which key
managers have pinned high expectations and it's frustrating to me to
hit so many walls over what I had presumed to be minor details. I
can create this app in VB6. I can even create it in vb.net winforms.
But for various reasons I prefer asp.net webforms. And I hate having
to call it quits, but it sure looks like I'll have to. A shame. I
was really excited at what I thought asp.net could do.


I don't think you have to call it quits. However, I do think (as I've said
before) that you need to do some work up-front in understanding the
achitecture you are using. Doing so will ease your frustration and will
allow you to create better and more robust applications.

--
Jim Cheshire
================================
Blog: http://blogs.msdn.com/jamesche

Latest entry:
Getting the PID and TID of a COM Call

Describes how to get the PID of the
dllhost process a COM call is executing
in and how to locate the thread as well.
 
R

Randall Arnold

"2. Impersonate a privileged user who can run CACLS.

Number 2 is the strong recommendation, and in this type of scenario, it
would be strongly advisable to use code-level impersonation."

The only thing that led me to CACLS was, as I said, suggestions to allow IIS
to run aspx pages on my laptop. I reall don't care WHAT method I use, as
long as it works. Again, no suggestion I've tried has worked. All have
produced errors. I've given up on this for the time being.

"This is not an
architectural flaw. It simply has to do with the fact that Windows
applications are designed to be run by the one person logged into the
console and not by a large number of users accessing a Web application"

I'm thinking I didn't make myself clear.

I don't want several users trying to run a single Windows app. I want the
asp.net page firing up a *local* copy of the necessary app(s) as needed
(ergo, MULTIPLE local instances). I had assumed this would be no big deal.
I understand your explanation about server-run apps but since that's not
what I want to do I'm thinking there shouldn't be a problem. If what I want
to do CAN'T be done, then I'm flabbergasted, and not due to lack of
familarity with the platform-- this appears to me to be a no-brainer. If
intranet users can't rely on a server-based app to automate the Office apps
on their desktop, why not? I'm not looking for interactivity anyway: I
simply want to automate (one way) the publishing of charts, tables and
graphics that reside on an intranet web page into various Office document
forms. I thought this was part of the office automation Nirvana MS has been
advertising for years.

My head is spinning.

Randall Arnold
 
J

Jim Cheshire

Randall said:
The only thing that led me to CACLS was, as I said, suggestions to
allow IIS to run aspx pages on my laptop. I reall don't care WHAT
method I use, as long as it works. Again, no suggestion I've tried
has worked. All have produced errors. I've given up on this for the
time being.



Understood. My point is that without knowing what errors you received,
there's no way to help. However, whomever told that you running CACLS from
your ASP.NET pages is a solution to ASP.NET pages not running is dumber than
a sack of hammers. How are you supposed to run CACLS from your ASP.NET page
if your ASP.NET page won't run? :)

I don't want several users trying to run a single Windows app. I
want the asp.net page firing up a *local* copy of the necessary
app(s) as needed (ergo, MULTIPLE local instances). I had assumed
this would be no big deal. I understand your explanation about
server-run apps but since that's not what I want to do I'm thinking
there shouldn't be a problem. If what I want to do CAN'T be done,
then I'm flabbergasted, and not due to lack of familarity with the
platform-- this appears to me to be a no-brainer. If intranet users
can't rely on a server-based app to automate the Office apps on their
desktop, why not? I'm not looking for interactivity anyway: I simply
want to automate (one way) the publishing of charts, tables and
graphics that reside on an intranet web page into various Office
document forms. I thought this was part of the office automation
Nirvana MS has been advertising for years.

Not much more I can say here. Office was not designed to work this way.

--
Jim Cheshire
================================
Blog: http://blogs.msdn.com/jamesche

Latest entry:
Getting the PID and TID of a COM Call

Describes how to get the PID of the
dllhost process a COM call is executing
in and how to locate the thread as well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top