Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using 'Save As' file menu through code for web browser control

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Obviously, it's reasonably straight forward to display a html document using the Web browser control, but what I need to do is programmatically instruct the web browser control to save the currently displayed document as a text file.

This can easily be manually simulated in IE by doing...

- File
- Save As...
- and then changing the Save as Type option to .txt (you also need to explicitly put.txt after the file name else it seems to ignore the fact that you've chosen .txt as the file type)

Any ideas gratefully received!
 
I think you can just use the standard Windows file dialog box. Check out this code:
VCA.gif

Alt255@Vorpalcom.Intranets.com
 
Wow, thanks for coming back so quickly (First post ever from me).

However, what I'm trying to achieve needs to be completely seemless. i.e. performed completely in code where I will decide the filename etc.

Any further ideas?

Cheers!
 
Okay, how about this...
Code:
Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
    "URLDownloadToFileA" (ByVal pCaller As Long, _
    ByVal szURL As String, _
    ByVal szFileName As String, _
    ByVal dwReserved As Long, _
    ByVal lpfnCB As Long) As Long

Public Function DownloadFile(URL As String, _
    LocalFilename As String) As Boolean

    Dim lngRetVal As Long
    
    lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    
    If lngRetVal = 0 Then DownloadFile = True

End Function

DownloadFileName$ = "[URL unfurl="true"]http://www.tek-tips.com"[/URL] 
TargetFileName$ = "C:\tek-tips.htm"

Retval = DownLoadFile(DownloadFileName$, TargetFileName$)

You would substitute address opened in your browser for " and create a unique name for the TargetFile$.

Hope this works for you.



VCA.gif

Alt255@Vorpalcom.Intranets.com
 
Thanks for the above, but the code you've supplied actually downloads the source text to a specified file. What I'm after is to create a text file that when viewed, represents (as best as is possible) the text as it appears in the browser.

Obviously, this isn't going to work very well with complicated frames pages, but the pages I'm looking to translate into text files are very simple business documents.

Any further ideas? Is there an argument in this API call which will carry out the above perhaps?

Cheers in advance for all your help!
 
Here's a cheap solution. Use Sendkeys to send Ctrl+A, then Ctrl+C, then use Clipboard.GetText to place the clipboard contents into a string variable. Then SendKeys the TAB character to clear the highlighted text.

Finally, write the variable to a text file. The output could be messy without page formatting and carriage returns but I can't think of a practical way to capture the screen text to a file.

Many apologies. Perhaps another member knows a convenient way to do this.

VCA.gif

Alt255@Vorpalcom.Intranets.com
 
Thanks again for your reply, but it has to be done programatically, without internet explorer being loaded.

Cheers again. Anybody else any ideas??
 
One more and I'll give up. Couldn't you parse the text from the html's downloaded using the previous example?

Nobody else seems to be responding to this thread.

Interesting problem. Good luck and post back when you find a workable solution.


VCA.gif

Alt255@Vorpalcom.Intranets.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top