Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 19th, 2006, 12:00 PM
Authorized User
Points: 382, Level: 6
Points: 382, Level: 6 Points: 382, Level: 6 Points: 382, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: Rawalpindi, -, Pakistan.
Posts: 73
Thanks: 0
Thanked 1 Time in 1 Post
Default mshtml - how to get images

I am working in a desktop application using .NET/C#. I have written a function which gets a url as an input parameter and matches all opened browser windows with this and returns the html contents
of the document if window found. This is done very successfully. For this purpose i am using ShDocvw.dll and mshtml.dll. The problem is that i want to get images from this (DHTML) document as byte array or as a file whatever is possible. I tried hard to explore it but couldn't yet succeed. Anybody out there to help me. I'll be grately thankful.

        public static string GetIEDocContents(string Url)
        {
            SHDocVw.ShellWindows objWins = new SHDocVw.ShellWindows();
            mshtml.HTMLDocument objDoc;
            string strContents="";
            object refIndex = 1;

            foreach(SHDocVw.InternetExplorer objIE in objWins)
            {
                if(objIE.LocationURL==Url)
                {
                    objDoc = (mshtml.HTMLDocument) objIE.Document;
                    strContents= objDoc.body.parentElement.innerHTML;
                    if(strContents.IndexOf("<FRAME")>=0)
                    {
                        mshtml.FramesCollection objFrames = (mshtml.FramesCollection) objDoc.frames;
                        mshtml.IHTMLWindow2 objFrame = (mshtml.IHTMLWindow2)objFrames.item(ref refIndex);
                        strContents=objFrame.document.body.parentElement.i nnerHTML;
                    }

                    break;
                }
            }

            return strContents;
        }



BaburMan
__________________
BaburMan
Reply With Quote
  #2 (permalink)  
Old May 24th, 2006, 03:01 AM
Authorized User
Points: 382, Level: 6
Points: 382, Level: 6 Points: 382, Level: 6 Points: 382, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: Rawalpindi, -, Pakistan.
Posts: 73
Thanks: 0
Thanked 1 Time in 1 Post
Default

Well, no repsonse from anywhere , for the time being i have to parse the html i have got for the images i want and got them
from the web using webclient object provided by .NET. Although this is not an efficient solution yet it works and servers the purpose.


thanks



BaburMan
Reply With Quote
  #3 (permalink)  
Old May 24th, 2006, 06:25 AM
Friend of Wrox
 
Join Date: May 2006
Location: Delhi, Delhi, India.
Posts: 106
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Will u please send me coding of the function to get containts of particular url's browser window at bijgupt@yahoo.com

Bijgupt
Reply With Quote
  #4 (permalink)  
Old May 26th, 2006, 12:30 PM
Authorized User
Points: 382, Level: 6
Points: 382, Level: 6 Points: 382, Level: 6 Points: 382, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: Rawalpindi, -, Pakistan.
Posts: 73
Thanks: 0
Thanked 1 Time in 1 Post
Default

The code i have posted above works perfectly provided you give a valid url from any of the opened internet explorer window on your machine. However as i mentioned you have to add a reference of microsoft.mshtml.dll and shdocvu.dll to your C# project.




BaburMan
Reply With Quote
  #5 (permalink)  
Old June 9th, 2006, 06:18 AM
Authorized User
Points: 382, Level: 6
Points: 382, Level: 6 Points: 382, Level: 6 Points: 382, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: Rawalpindi, -, Pakistan.
Posts: 73
Thanks: 0
Thanked 1 Time in 1 Post
Default

Successfully got the url source and the images at least. But still i need to find the way to get the css, js and swf. Obviousely css and js script should be grabbed as text and swf as a binary stream or in the form which could be saved to disk. Still waiting from anybody to help or give any link which describes how to accomplish this. The source is as below;

public static string GetIEDocContents(string Url)
{
    SHDocVw.ShellWindows objWins = new SHDocVw.ShellWindows();
    mshtml.HTMLDocument objDoc;
    string strContents="";
    object refIndex = 1;

    foreach(SHDocVw.InternetExplorer objIE in objWins)
    {
        if(objIE.LocationURL==Url)
        {
            objDoc = (mshtml.HTMLDocument) objIE.Document;
            strContents= objDoc.body.parentElement.innerHTML;
            if(strContents.IndexOf("<FRAME")>=0)
            {
                mshtml.FramesCollection objFrames = (mshtml.FramesCollection) objDoc.frames;
                mshtml.IHTMLWindow2 objFrame = (mshtml.IHTMLWindow2)objFrames.item(ref refIndex);
                strContents=objFrame.document.body.parentElement.i nnerHTML;
            }

            string strElName;
            mshtml.IHTMLElement2 body2 = (mshtml.IHTMLElement2) objDoc.body;
            mshtml.IHTMLControlRange controlRange = (mshtml.IHTMLControlRange) body2.createControlRange();
            mshtml.IHTMLElementCollection objElCol;
            objElCol = objDoc.getElementsByTagName("IMG");

            foreach(mshtml.HTMLImg objImg in objElCol)
            {
                controlRange.add((mshtml.IHTMLControlElement)objIm g);
                controlRange.execCommand("Copy", false, System.Reflection.Missing.Value);
                controlRange.remove(0);
                strElName = objImg.nameProp;

                if (Clipboard.GetDataObject() != null)
                {
                    IDataObject data = Clipboard.GetDataObject();

                    if (data.GetDataPresent(DataFormats.Bitmap))
                    {
                        Image image = (Image)data.GetData(DataFormats.Bitmap,true);
                        if(strElName.Substring(strElName.IndexOf(".")+1).T oLower()=="jpg")
                            image.Save(@"c:\images\"+strElName, System.Drawing.Imaging.ImageFormat.Jpeg);
                        else if(strElName.Substring(strElName.IndexOf(".")+1).T oLower()=="gif")
                            image.Save(@"c:\images\"+strElName, System.Drawing.Imaging.ImageFormat.Gif);
                        else
                            strElName = strElName; //to put a breakpoint and debug to see what's this.
                    }
                    else
                        strElName = strElName;
                }
            }


            break;
        }
    }

    return strContents;
}

BaburMan
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Load Images from and Save Images to a Database cyndie VB.NET 2 August 17th, 2008 06:42 AM
Problems using MSHTML maccas Pro VB 6 2 February 15th, 2006 11:32 AM
How to use MSHTML in Visual Basic 6? raylynn Pro VB 6 1 November 18th, 2005 09:36 AM
mshtml COM script events daveyc Pro VB.NET 2002/2003 0 June 15th, 2005 01:44 PM
Problem using MSHTML maccas Excel VBA 1 November 3rd, 2004 08:04 AM



All times are GMT -4. The time now is 01:13 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.