|
The following code is probably the most common code on the net for automating IE with Excel.
Sadly when I use it I get an automation error stating "Method Busy of IWebBrowser2 failed" (The Bold Part)...
Can anybody help me out how to tackle this error?
Sub Button1_Click
Set myIE = CreateObject("InternetExplorer.Application") 'New '
Dim myURL As String
Dim strSearch As String
'Set starting URL and search string
myURL = "http://google.com"
strSearch = "Infosys"
'Make IE navigate to the URL and make browser visible
myIE.Navigate myURL
myIE.Visible = True
'Wait for the page to load
Do While myIE.Busy Or myIE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop
'Set IE document into object
Set myDoc = myIE.Document
'Enter search string on form
myDoc.forms(0).q.Value = strSearch
'Submit form
myDoc.f.submit
'Wait for the page to load
Do While myIE.Busy Or myIE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop
'MsgBox myIE.LocationName
End Sub
|
|
|
|
|
Hi,
I am trying to load a word doc and save it into a table.
I have a column for the file document as type image in the table.
when i doubleclick to select the file it throws an exception because the file type .
dim docs as system.drawing.image
me.openfiledialog.showdialog()
docs=system.drawing.bitmap.fromsream(me.openfiledialog.Openfile,true)
me.PicturePictureBox.image=docs
Guide me please
Thanks :
|
|
|
|
|
The error is due to the Word document not being an image file, such as a Bitmap or JPEG. Don't confuss a SQL Image type as a picture. Search Google on BLOBs
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
Thanks for repling..
I agree but I am not getting a good result on the search from google..
the word document is binary type or bites..
the file is from filestream..
so where lies my problem in getting the right type
thanks
|
|
|
|
|
Why are you even bothering with creating an Image object with a Word document?? The Image class is for handling, well, picture, .BMP, .JPG, .PNG files... not Word documents.
After seeing code like this, I'm quite sure you've got a mountain of other things wrong, so without seeing the code that you're using to setup the SQL INSERT operation, it's impossible to tell you where you went wrong.
|
|
|
|
|
Thanks,
let's do away with my initial coding.
what I want to accomplish in a form is to be able to upload .doc, text, rtf, pgf files and save it to a table..
Upload() will load the document from the file path and put the path into a richtextbox and save it in a table.
viewdocumentclick() will read the document in its format.
Hope I am a bit clearer now..
Thanks alot
|
|
|
|
|
All you're doing is saving a stream of bytes to the database, just like saving an image file. Every file is nothing but a stream of bytes.
' This is array is holding the contents of your file.
Dim fileContents() As Byte
.
.
.
myConnection = New SqlConnection(CONNECTION_STRING)
Dim myCommand As New SqlCommand("INSERT INTO someTable (FileData) VALUES (@Image)", myConnection)
Dim myParameter As New SqlParameter("@Image", SqlDbType.Image, fileContents.Length)
myParameter.Value = fileContents
myCommand.Parameters.Add(myParameter)
myConnection.Open()
myCommand.ExecuteNonQuery()
|
|
|
|
|
Thanks again,
I am using Vb.net(Visual Studio) and SqlExpress where I am using Dataset and TableAdapter.
I just need to click on a command to open the directory, select the file and load it or the path of it into the richtextbox and the savecommand_click() save everything..
On read, readcommand_click() read the file in its format and not being able to edit the document.
thanks
|
|
|
|
|
...and...so, what's the question? I just showed you how to save data to an SQL Server. I have no idea what you're asking now...
|
|
|
|
|
Hi Dave,
The question is not actually saving the information. My question is how to open the folder, retrieve .doc, .txt file, like you will do with an image.
thanks
|
|
|
|
|
Wait, wait, wait... You've already got the hard part done, but can't manage the easy part?
You're looking for the OpenFileDialog in the Toolbox. It'll give you the filepath that the user selected. After that, just tell the RichTextBox what the file path is.
What this tells me is that you've been copying 'n pasting code from all over the web looking for something that does what you want it to do. Correct?
|
|
|
|
|
Hi,
back to my very first question, I can get to the folder, when selecting the file, it throws an exception because of image type record..this column should be of image type since on other occasion scanned document will be inserted there.
Hope you understand me now.
thanks alot
|
|
|
|
|
This doesn't make any sense. Are you saying that you want a "scanned image" of the Word, or some other, document, page-by-page??
|
|
|
|
|
The word document can be on a USB to upload or if only a hard copy exists then the hard copy can be scanned to upload.
thanks
|
|
|
|
|
OK, that doesn't answer my question.
|
|
|
|
|
Hi,
here is the cenario:
a form will capture user informations. One richtextbox is for loading a grievance letter which can be a soft copy or a hard copy. if it is a hard copy, it will be first scanned and placed in a folder. Then the application will load it from the folder.
if it is a soft copy, meaning from a USB Flash drive, the app will get it from there.
Hope I am clearer now
thanks
|
|
|
|
|
So? What's so hard about an OpenFileDialog?? What's difficult about calling the RichTextBox's LoadFile method??
|
|
|
|
|
Hi Dave,
Can you shed some light on this?
Dim docs as System.Drawing.Image
ME.OpenFileDilogue.ShowDialog()
docs=System.Bitmap.Drawing.FromStream(Me.OpenFileDialog.OpenFile,True)
Me.PictureBox.Image= docs
My problem is that firstly in the table, the record is of type image
secondly, file that i am selecting is not an image therefore the file cannot be loaded.
I tried to have the record type as bytes and use it as Filestream. No luck..
Maybe you can guide me
Thanks
|
|
|
|
|
waner michaud wrote: My problem is that firstly in the table, the record is of type image
"Image" in the database means any blob of binary data, not a picture.
The first line of code in your snippet is garbage. It refers ONLY to pictures or drawings. It can NOT load a Word document, nor a .TXT file, nor an .RTF, or any other non-picture format. And no, there is no class or method in the .NET Framework that will convert these formats into a "picture" of a page.
waner michaud wrote: Maybe you can guide me
I have no idea what you're ultimately trying to do with this code. Are you trying to save a picture of a Word page, or are you trying to save the Word document itself in the database??
|
|
|
|
|
.....
openFileDialog.Filter = "Word Files|*.DOC" ?
|
|
|
|
|
Hardly the point of his problem. This is just one tiny aspect of using the OpenFileDialog. He's got much bigger issue with his design, including the inability to describe the specification of his app, the design, and what he's ultimately trying to do.
|
|
|
|
|
Hi Dave,
I got this issue solved. I have the path of the file saved in a table.
Now what I want to do is when I load this table, I want to click on a command to read this this file in its format.
Let's say if it is a word document, it will launch msword and the file..for that matter any other format..
thanks
|
|
|
|
|
Launch the full path to the document using the Process class. It'll launch the default editor for that document just like you double-clicked the icon yourself.
|
|
|
|
|
I am currently creating a visual studio plugin for my group. When we are trying to add a new item to the database we click add new item button, another window opens. You add the information and press the okay button. Out of no where the application freezes and gives us a window stating that .NET has encountered an error and shuts down giving you the option to restart. I have stepped through the code on various employees computers and it happens to everyone. Any suggestions on a fix???
|
|
|
|
|
Since you haven't given anny information on what's causing the error, nor the error message, there's little to nothing anyone can tell you on how to fix it.
|
|
|
|