locked
How to paste any Image from file and any word document file to web browser control using c#? RRS feed

  • Question

  • Hello All,

    I am developing a windows form and i am trying to paste image(s) from file or any word document file to webbrowser control using c#, so how it is possible for me?

    Thanks,

    • Moved by Kevin Linq Monday, September 26, 2016 9:16 AM
    Saturday, September 24, 2016 6:56 AM

All replies

  • Do you want to replace the current contents of WebBrowser with an image, or to insert the image to some specific place of the Web page? Give some details.

    But an image (Image object, loaded from file using Image.FromFile), can be shown easier using a PictureBox control. Then WebBrowser control is not needed, or can be hidden.

    Saturday, September 24, 2016 8:11 AM
  • Thanks Viorel,

    Webbrowser control is mandatory for me bcz of issue is not only image but also need to paste text and image(s) because of i am using browser as text editor. And also don't want to refresh a web page or load a new web page.


    • Edited by H J SOFT Saturday, September 24, 2016 9:28 AM
    Saturday, September 24, 2016 9:26 AM
  • Thanks Viorel,

    Webbrowser control is mandatory for me bcz of issue is not only image but also need to paste text and image(s) because of i am using browser as text editor. And also don't want to refresh a web page or load a new web page.


    You are using the Webbrowser as a text editor? Okay, a lot more information is needed.

    Like why are you doing it like that in the first place? Why are you using a webpage as editor? As Editor for what exactly?
    Are you trying to automate the Editors Feature of inserting a Image into the Document? That will not be done by adding the image to your local copy of the Page.


    Remember to mark helpfull answers as helpfull and close threads by marking answers.

    Saturday, September 24, 2016 9:14 PM
  • for accessing image(s) from a word document you have to use the Word PIA (Primary Interop Assembly). Down are the links which helps you to get started.

    Office Primary Interop Assemblies

    Walkthrough: Office Programming (C# and Visual Basic)

    Sunday, September 25, 2016 4:23 AM
  • Thanks Viorel,

    Webbrowser control is mandatory for me bcz of issue is not only image but also need to paste text and image(s) because of i am using browser as text editor. And also don't want to refresh a web page or load a new web page.


    A WebBrowser control isn't really a good idea for this purpose as that is not what it is designed for.

    A RichTextBox can have images and text pasted into it from the Clipboard or dragged from another apps window and dropped onto it which also uses the Clipboard.

    A WebBrowser control is typically used to display what HTML/CSS/Java Script instructions tell it to display. Without having HTML/CSS instructions for the WebBrowser control to display images and text how is it supposed to know where to place information for text or for images where to get them from to display them?

    I don't know if an animated .Gif will run in a RichTextBox like it will in a WebBrowser control cause I've never tried that. But a RichTextBox will display images and text and that information can be saved as .RTF.


    La vida loca

    Sunday, September 25, 2016 4:51 AM
  • Maybe this is what you are looking for. If so your explanation is poor for what you desire and I don't know if it accepts drop from another source.

    Carls Blog - WinForms HTML Editor

    WinForms HTML Editor


    La vida loca

    Monday, September 26, 2016 12:11 AM
  • Hi H J SOFT :

    Thank you for posting here.

    Since your issue is related to Win form development, I will move your thread to Windows form general forum . 

    The Visual C# forum discuss and ask questions about the C# programming language, IDE, libraries, samples, and tools.

    If you have some grammar or code errors, please feel free to contact us. We will try our best to give you a solution.

    Here is the link of Winform general forum:https://social.msdn.microsoft.com/Forums/windows/en-US/home?category=windowsforms

    If you have anything else regarding C# programming , please feel free to let me know . 

    Best Regards,

    Kevin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Monday, September 26, 2016 9:15 AM
  • Thanks to all,

    I have not a single issue with use of rich text box. But I have a question regarding rich text box.

    Question:

    If rich text box contain text and Image(s) then this control can convert image(s) to base64 string or base64 to image? If possible then how it works?

    Monday, September 26, 2016 1:09 PM
  • Thanks to all,

    I have not a single issue with use of rich text box. But I have a question regarding rich text box.

    Question:

    If rich text box contain text and Image(s) then this control can convert image(s) to base64 string or base64 to image? If possible then how it works?

    Base64 encoding is usualyl used when you want to send some binary data (like images) over the Internet (mail and webpages in particular). And RTF is somewhat convertible into HTML, so we are back at you trying to edit a webpage.

    Again what is your editor/programm doing. We can not help but feel that you are on a totally wrong track for a rather simple problem (like producing a HTML Mail).


    Remember to mark helpfull answers as helpfull and close threads by marking answers.

    Monday, September 26, 2016 1:39 PM
  • Thanks Christopher

    I am developing a windows application to transfer data between two or more than pcs. or some time using internet also so, need to convert image as base 64 string.

     

    Tuesday, September 27, 2016 4:42 AM
  • Hi HJ,

    Have your original issue related with paste any Image from file and any word document file to web browser control been resolved?

    Have your issue related with RichTextbo been resolved?

    It would be helpful if you could share us more information about your current issue.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, September 29, 2016 9:09 AM
  • Thanks Christopher

    I am developing a windows application to transfer data between two or more than pcs. or some time using internet also so, need to convert image as base 64 string.

     

    Well if you want to transfer an Image in a RichTextBox as well as text richly formatted then all you have to do is transfer the RichTextBox's RTF.

    If you try a RichTextBox and paste an image to it or use the drag/drop capability to drag an image onto it (which I'm fairly certain it will do) then you can save the RichTextBox's RTF to a file using appropriate code. If you edit the saved file in Notepad it is just text. I would guess that RTF uses base 64 string for the images data but haven't read the spec to verify that.

    Update: I used an app I already had that copied and pasted a 20 x 20 pixel image into a RichTextBox then saved the RichTextBox.Rtf to a text file since it is just text. Below is the Rtf and below that the image of the app with the small image in the RichTextBox.

    I'm not certain why you require a base 64 string. Via IP you could compress this data and use an HTTP Web Request or WebClient to upload/download data or even use a TCP server and have your other systems access that with TCP client to get data. Unless the whole idea is something that only uses WebBrowser so the end users only have to use a standard WebBrowser and not some app you wrote.

    {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}
    \viewkind4\uc1\pard\f0\fs29{\pict\wmetafile8\picw529\pich529\picwgoal300\pichgoal300 
    0100090000039002000000007a0200000000050000000b0200000000050000000c02110211027a
    020000430f2000cc00000014001400000000001102110200000000280000001400000014000000
    0100180000000000b0040000c40e0000c40e000000000000000000000202020202020202020202
    020202020202020202020202020202020202020202020202020202020202020202020202020202
    020202020202020202020403030000000000000403030403030403030403030101000302020403
    030403030403030403030403030403030403030403030201010100000403030000001110101010
    1000000003010102000000000018183f0506080200000301010301010301010301010301010301
    010100000a07070b0909000000242222d6d5d5adadad0000000200000200000608003335ff0805
    060100000200000200000200000200000200000200000000007d7d7de9e8e8000000403f3fdddd
    ddececec0000000000001010283433c82c34ff0708000000000000000000000200000301010200
    000000001a1919dadadad0cfcf7d7c7cbdbdbdcdcdcdefefef949292000000272cbe2b2ed72d31
    e102002463625d605e5e5c5b5b0000000200000000000c0b0bd9d9d9ffffffe2e2e2c9c9c93331
    31e9e8e8fffffff0f0f092937f1e1bd92630d91616c7999ca8f8f9f6e6e7e6ffffff504e4e0000
    00343232f4f3f3feffff5455555c5c5c4848480000000000000000006e6c6cfffff42528a42223
    ce62629ddfddcf403e3f1a191b605f60c9c8c8666464f5f5f5dbdbdb0000000000000000000000
    00020000020000000000000000000000554fa1201fba8c91a87f7d7c797877b5b4b67c7c7c8988
    88d7d6d69292920000000000000300000300000300000301010301010301010200000000000f38
    362c7e9c615954c8c6c6b7b7b79f9f9fffffff8282825a5b5b0000000200000301010301010301
    01030101030101030101030101020000020000283cd8c0cdc5868583b6b5b69d9c9e0f0d10f0ef
    f0dededed1d1d12c2b2b0000000301010301010301010301010301010301010301010200000000
    001318a43f417a0b0802020005646365ebebec0a090c000000b3b2b3312f300000000301010301
    010301010301010200000200000200000000000806057a775a1c1fc7656a69515043424042abac
    ab4342432b292cb1b1b28684800000000000000200000301010301010000000000000000002624
    24c7c7c7fdfdf12f34a81c21eb7e83db5f5c50fffffafffff8ffffffffffef9193b5dedbd8302e
    2e000000000000000000646363848383818080ffffffdddcdc0200002124942e2ecb212df61d26
    f92424506163dc6f75d64344c2010037b4b4aeffffff7473734c4c4c0707078a8a8ae4e4e4ffff
    ff9f9f9f0000000000000d0d083233cf2931f52a32f12629cf1f236d2227ce2c2db60201020000
    00646363d0d0d0e1e2e2b3b3b3858585dadadaececec0000000000000300000000000e0c162e2e
    a42c30ec2e37ff3330f62c2a90040400010000030000000000e5e5e5e5e5e5292929101010b0b0
    b04a4a4a0000000101010101010101000000000000000507041311290204000000000000000101
    00010101000000282828e9e9e90000000000000000000000000303030303030303030303030303
    030203020202000101000202000303030303030303030303030303030000000000000101010303
    030303030303030303030303030303030303030303030303030303030303030303030303030303
    03030303030303030303030303030303030303030000000000
    }\par
    }
    


    La vida loca

    Friday, September 30, 2016 6:26 PM
  • If you want to paste image in a webbrowser control, you have to use the CF_HTML format. It is basically HTML plus a header and I guess you don't need help in writing an HTML document containing image elements. 

    Microsoft's FrontPage is based on richedit BTW. 



    Visual C++ MVP

    Monday, October 3, 2016 9:54 PM