Is it possible to save a file of any type bypassing the 'save as' dialog? using the WebBrowser Class
WebBrowser.ShowSaveAsDialog();
Is the loaded content in a WebBrowser control serializable so it can be saved and retrieved (for redisplay)?
Given that you have full access to the DOM and can therefore read any contents that the WebBrowser is displaying the answer must be yes.
Using the tree of DOM nodes read the contents of the WebBrowser into the C# world
Write to the file using normal .NET file access
However if you just wish to download a webpage and save it to disk there are better ways then using the WebBrowser control, have a look at the WebClient class
I see this is an old question, but I'm just going to update with a possible alternative.
Please take a look in this CodeProject article.
Related
I use ITextSharp to create a PDF with form data based on another PDF.
The problem is the file generated is not editable (the form on it).
If I use ITextSharp in append mode, I get the form editable but most of the form data is not preserved. I want the user to see the resulted PDF with the PDF Form data preserved.
I understand there is NOTHING I can do. The only way for the user to edit the resulted PDF is to use a paid Acrobat version on it. This is because I CHANGE the PDF file by entering form data and setting fonts on it.
Is there something I can do?
Paul
Your question isn't very clear, but here are some answers to similar questions that have been asked before:
End users can't edit a form locally unless the form is "reader-enabled". Making a form reader-enabled is only possible when you use Adobe software: "Adding Enable for commenting Adobe Reader" using Acrobat
You need to fill out reader-enabled forms in append mode if you don't want to break the reader-enabling: Pdf with Acroform editing using iText
This doesn't mean you can't ask people to fill out a PDF form to gather data. See
Edit pdf embedded in the browser and save the pdf directly to server
You can capture that data, and fill out the form without flattening if you want to serve this form (including the data) to the end user: How to fill out a pdf file programmatically?
I'm pretty sure one of these question is a duplicate of what you're asking, but since your question isn't clear, it's hard to mark your question as an exact duplicate of one of them.
Short answer: No
Pdf file are likely to be secure (read only) and this is why everyone is using it. Most of the time, we convert a file into a pdf so maybe if you can get the 'file' and not the pdf will be a good move there.
From my experience in the past, I can confirm with you that iTextSharp may not convert all your data properly and this can make your generated file unusable. If not, you might have some weird line or some changes in the document behavior (ex. fields are not editable anymore).
If you really want to work with pdf file as input and do your stuff with it, you will need to understand the inner structure of it:
[PDF file format]
http://resources.infosecinstitute.com/pdf-file-format-basic-structure/
This can be a hell of a ride. You might need to re-consider the use of a pdf as input. If you can't change that, you might need to use some sort of adobe pluging to do so. Alot of third party pdf library is doing that.
Good luck
The WebBrowser control has a method named ShowSaveAsDialog() which can save a loaded document into a file. I want to find out the path of the saved file and open it. How can I find such a path or an alternative way to save an html file loaded by WebBrowser control.
It seems you want to save everything to a web archive (.mht) file. I can't see that anyone has got that working via the WebBrowser control.
However, there are alternatives for doing this programatically. Jeff Atwood posted an article on CodeProject: Convert any URL to a MHTML archive using native .NET code but it's in VB.NET. Incidentally, Jeff is one of the co-founders of this site and is Stack Overflow Valued Associate #00001!
Someone has kindly ported Jeff's code to C# and that can be found on Google Code here: url2mhtml
Also see this question: generate .mht file programmatically
I am trying to obtain html from the WebBrowser control, but it must include the value attributes of input elements on the page as well.
If I use webBrowser.DocumentText, I get the full HTML of the page as it was initially loaded. The input field values are not included.
If I use webBrowser.Document.Body.OuterHtml, I get the values, but not the other contents of (), which I need so I can get the stylesheet links, etc.
Is there a clean dependable way to obtain the full HTML of the DOM in its current state from the WebBrowser? I am passing the HTML to a library for it to be rendered to PDF, so suggestions for programmatically saving from the WebBrowser control to PDF will also be appreciated.
Thanks
There are some undocumented ways (changing registry, undocumented dll export) to print the document to XPS or PDF printers without parsing the page, that is, if your can afford to roll out required printer drivers to your customer's network.
If you want to parse the web page, documentElement.outerHTML should give you the full canonicalized document, but not the linked image, script or stylesheet files. You need to parse the page, enumerate elements and check element types and get resource urls before digging the WinInet cache or downloading for additional resources. To get the documentElement property, you need to cast HtmlDocument.DomDocument to mshtml.IHTMLDocument2 if you use Windows Forms, or cast WebBrowser.Document to mshtml.IHTMLDocument2 if you use WPF. If you need to wait before the Ajax code finishes execution, starting a timer when the DocumentComplete event is raised.
At this stage, I would parse the HTML DOM and get the necessary data in order to generate a report via a template, so you always have the option to generate other formats supported by the report engine, such as Microsoft Word. Very rarely I need to render the HTML as parsed, for example, printing a long table without adding customized header and footer on each page. That said, you can check Convert HTML to PDF in .NET and test which one of the suggested software/components works best with your target web site, if you do not have long tables.
I need to Embed the Word Document in silverlight,and i need to have all the same functionality of Word Document.
Like Cut,Copy,Paste,Save,Save us,Formating Etc.
How can i Achieve this?.
Also Suggest me some links too.
SL4 comes with COM automation support mean if client machine has Word installed SL can use it to display work doc:
http://forums.silverlight.net/forums/p/185680/424357.aspx
http://www.silverlightshow.net/items/MS-Word-Mail-Merge-with-Silverlight-4-COM-Automation.aspx
If you are using SL3.. it will be a little daunting... may be you will have to find some RTE to display word in it.
Regards.
The problem with using the COM model to read the file is that you must run the Silverlight app out of the browser with Elevated privileges and the user mush have Word installed so not very useful if you want a web app.
However Word documents are storred as XML files inside a zipped file (rename file from name.docx to name.zip to see the files) so you could always write a class to read in the XML and display it inside a Rich Text Box and then after formatting write it out to a XML form, this will take a lot of effort.
I'm trying to create a notepad/wordpad clone. I want to save it in .rtf format so that it can be read by wordpad. How do I save a do this in C#?
Assuming you are trying to do this yourself for learning purposes, you don't want to use a library to do it for you:
Basically you need to write a program which holds in memory either a string with RTF markup, or a DOM-like data tree. Using the RTF specification, you should write a flat (text) file marked up properly and with a .rtf extension. Just the same as if you were writing an HTML file.
Correct me if I'm wrong, but if you're using the RichTextBox control, you can just use the RichTextBox.SaveFile method to accomplush this. Just a guess though that you mean doing it without using that control.
RTF SpecLink
create the xml spec based on their api and you can make your app compatible with wordpad, word etc.