Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I'm navigating using the webbrowser in the end i'm getting to webbrowser4 document completed event.

At this point i have in the webbrowser already the page to add a message. I also can give the message a title.

Now i want to add to this message attached image/s. The problem is how to attach the images.

C#
void webBrowser4_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {

            if (e.Url.AbsoluteUri != webBrowser4.Url.AbsoluteUri)
            {
                return;
            }

            HtmlElementCollection items = webBrowser4.Document.GetElementsByTagName("div");
            foreach (HtmlElement item in items)
            {
                if (item.GetAttribute("className") == "elements")
                {
                    webBrowser4.Document.GetElementById("ctl00_RightMainContent_txt_subject").InnerText = "Hello world";
                }
            }

            HtmlElementCollection classButton = webBrowser4.Document.All;
            foreach (HtmlElement element in classButton)
            {
                if (element.GetAttribute("className") == "addImg")
                {
                    element.InvokeMember("click");
                }
            }

            // uplFileDrgDrp
            HtmlElementCollection classButton1 = webBrowser4.Document.All;
            foreach (HtmlElement element in classButton1)
            {
                if (element.GetAttribute("className") == "uplFileDrgDrp")
                {
                    element.InvokeMember("click");
                }
            }
         }


First i'm adding a title to the message Hello World

Then i click on the button addImg

The last part should attach now the images. After i click addImg i can click on another button and browse to images i want to attach from my hard disk or i can drag and drop images to this addImg window. In any case i want to add this images without browsing or even without drag and drop them but i can't figure out how.

This is a screenshot of the website after clicked to add a new message:

screenshot[^]

My question is how can i attach the images i want automatic. Let's say i'm GetFiles and i have array of images and now i want to attach them to the message.

This is the whole add message page view-source link

When the window to drag and drop images is opened and i'm doing inspect element i see:


[^]

Maybe somehow to make that it will drag and drop automatic the images files from array of images. Not sure how to do it at all.

What I have tried:

What i tried is mentioned in the question you can see it here more clear here:

https://social.msdn.microsoft.com/Forums/vstudio/en-US/cc81eaf5-8f6b-479e-85c8-9cadd259ee3d/how-can-i-attach-automatic-images-to-container-in-a-web-page-using-webbrowser-control-?forum=csharpgeneral
Posted
Updated 8-Feb-16 8:53am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900