|
Hi there,
I am trying to make this work for the past three days but with no success. I have a windows form application with web browser control integrated into it. What i want is that when ever there is some file download request come along i get the url and download it via System.net classes, if the file is a word,excel or power point document i open them in my other form where i have integrated the word/excel/pp. all the rest of bits are working the only thing left is that i don't know how to intercept file download. I know i have to implement idownloadmanager interface but i can't make it work, my the download method of the interface never get called. the sample code is here
Imports System.Runtime.InteropServices
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Browser As AxSHDocVw.AxWebBrowser
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
Me.Browser = New AxSHDocVw.AxWebBrowser
CType(Me.Browser, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'Browser
'
Me.Browser.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.Browser.Enabled = True
Me.Browser.Location = New System.Drawing.Point(8, 8)
Me.Browser.OcxState = CType(resources.GetObject("Browser.OcxState"), System.Windows.Forms.AxHost.State)
Me.Browser.Size = New System.Drawing.Size(360, 304)
Me.Browser.TabIndex = 0
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(376, 318)
Me.Controls.Add(Me.Browser)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.Browser, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim url As System.Object = "http://my.mindvision.com/~ben/tools/"
Dim o As System.Object = Nothing
Browser.Navigate2(url, o, o, o, o)
SetDownloadManager()
End Sub
Private m_DownloadManagerCookie As System.Int32
Private Sub SetDownloadManager()
Dim ips As COMVB.IProfferService
Dim objBrowser As Object
Dim ispBrowser As COMVB.UCOMIServiceProvider
Dim ip As IntPtr
Try
' Get a handle to the browser ocx
objBrowser = Browser.GetOcx()
ispBrowser = DirectCast(objBrowser, COMVB.UCOMIServiceProvider)
' Query the browser for the IProfferService interface
ip = ispBrowser.QueryService(COMVB.SID_SProfferService, COMVB.IID_IProfferService)
ips = DirectCast(Marshal.GetObjectForIUnknown(ip), COMVB.IProfferService)
' Proffer the new object as the provider of the IHTMLEditHostinterface handler
ips.ProfferService(COMVB.IID_IDownloadManager, New ServiceProvider, m_DownloadManagerCookie)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Class
Class ServiceProvider
Implements COMVB.UCOMIServiceProvider
Public Function QueryService(ByRef guidService As System.Guid, ByRef riid As System.Guid) As IntPtr Implements COMVB.UCOMIServiceProvider.QueryService
If guidService.Equals(COMVB.IID_IDownloadManager) Then
If riid.Equals(COMVB.IID_IDownloadManager) Then
Dim idm As COM.Interfaces.IDownloadManager
idm = New DownloadManager
' idm.Download()
Return GetInterface(idm, COMVB.IID_IDownloadManager)
Else
Return Nothing
End If
Else
Return Nothing
End If
End Function
Public Function GetInterface(ByVal obj As Object, ByRef iid As Guid) As IntPtr
Dim pUnk As IntPtr
Dim pInterface As IntPtr
Dim hr As Integer
pUnk = Marshal.GetIUnknownForObject(obj)
hr = Marshal.QueryInterface(pUnk, iid, pInterface)
If hr < 0 Then
Marshal.ThrowExceptionForHR(hr)
End If
' Marshal.GetHINSTANCE()
' Marshal.Release(pUnk)
Return pInterface
End Function
End Class
Class DownloadManager
Implements COM.Interfaces.IDownloadManager
Public Function Download(ByVal pmk As System.Runtime.InteropServices.UCOMIMoniker, ByVal pbc As System.Runtime.InteropServices.UCOMIBindCtx, ByVal dwBindVerb As System.UInt32, ByVal grfBINDF As Integer, ByVal pBindInfo As System.IntPtr, ByVal pszHeaders As String, ByVal pszRedir As String, ByVal uiCP As System.UInt32) As Integer Implements COM.Interfaces.IDownloadManager.Download
MsgBox("file download event")
Return New System.Int32
End Function
End Class
Class COMVB
' IServiceProvider interface
<comvisible(true), comimport(),guid("6d5140c1-7436-11ce-8034-00aa006009fa"),="" _
interfacetypeattribute(cominterfacetype.interfaceisiunknown)=""> _
Public Interface UCOMIServiceProvider
Function QueryService(ByRef guidService As Guid, ByRef riid As Guid) As IntPtr
End Interface
' IProfferService interface
<comvisible(true), comimport(),="" guid("cb728b20-f786-11ce-92ad-00aa00a74cd0"),="" _
="" interfacetypeattribute(cominterfacetype.interfaceisiunknown)=""> _
Public Interface IProfferService
Sub ProfferService(ByRef guidService As Guid, ByVal psp As UCOMIServiceProvider, ByRef cookie As Integer)
Sub RevokeService(ByVal cookie As Integer)
End Interface
Public Shared SID_SProfferService As New Guid("cb728b20-f786-11ce-92ad-00aa00a74cd0")
Public Shared IID_IProfferService As New Guid("cb728b20-f786-11ce-92ad-00aa00a74cd0")
Public Shared SID_SHTMLEditHost As New Guid("3050f6a0-98b5-11cf-bb82-00aa00bdce0b")
Public Shared IID_IDownloadManager As New Guid("988934A4-064B-11D3-BB80-00104B35E7F9")
End Class
|
|
|
|
|
Hi everybody,
I have a vb.net windows application which is supposed to download a file on a remote IIS, how would you guys do something like that? I know I'll have to work with the http protocol, but have no clue on how to achive this.
Thank you in Advance,
/Peace2u my friends
|
|
|
|
|
Can anyone please help me. It's Urgent
I have to make a module for given below
In windows application with VB.Net. i have to make a application in that application There on SQL server thereare two databases one is blank and another has some data. But the tables in both the database are same. I want to transfer the data on the same sever in the blank databases through VB.Net coding. Also please give me the code for solving the problem of identity column. and some tables have relation with other tables how the data of thattables should be migrated.
divya
|
|
|
|
|
hi
I am not able to find the exact meaning of data compression algorithm(i.e deflate). is it any way related to data encryption or just creating an archive file? i have to implement this using the VB6. so please suggest me the best method to do that.
Kind Regards
Sandy
|
|
|
|
|
Are you working with data compression or data encryption?
|
|
|
|
|
Paul Conrad wrote: Are you working with data compression or data encryption?
Hi
its actually kind of doing both with the name of data compression. but i am not sure wat data compression actually means.
1) encrytping data to make the file size less?
2) Zipping it inorder to reduce the file size?
What exactly it is?
Kind Regards
Sandy
|
|
|
|
|
Data compression is to make the data smaller, reducing the size in memory or in a file. Data encryption is securing the data so unauthorized people cannot view the data. You can have both work together. For example, compress the data first, and then encrypt the compressed data. To undo the action I've just mentioned, you'd then decrypt the data and then uncompress the data for viewing, processing, etc. There are plently of compression libraries that can be googled and articles on this site.
Hope this helps,
Paul
|
|
|
|
|
Thank youvery much i think i can now be able to do my job. thanks for that suggestion
Kind Regards
Sandy
|
|
|
|
|
The best way to do it is to look for a component that will do it for you. Google results[^] for "vb6 data compression .zip".
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi there,
1. How to control the textbox allows alphabets only. i want to know is there any other method beside Keypress event().
2. how to control the textbox allows alphanumeric values. For example Ic No. S1234567D
- so i want 1st character to be Alphabet and other 7 be numeric and the last 1 be alphabet.
I'm thinking for 2 weeks still i couldn't find a solution. HELP ME!!
Thanx in Advance.
|
|
|
|
|
Simple programmer wrote: 1. How to control the textbox allows alphabets only. i want to know is there any other method beside Keypress event().
The only other place in the KeyDown event of the TextBox.
Simple programmer wrote: . how to control the textbox allows alphanumeric values. For example Ic No. S1234567D
- so i want 1st character to be Alphabet and other 7 be numeric and the last 1 be alphabet.
Same thing as #1. But the best method would be to use a RegEx expression to check the string in the TextBox, combined with the current KeyDown character, for the proper format.
Or you could just use a MaskedEdit control[^] to do the same thing... In VB.NET 2005, there's already one of these in the ToolBox.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi Dave,
Thanx a lot. i will try it out. Hope it works.
|
|
|
|
|
I have added refrence of microsoft flexgrid.
However , the toolbox could not show the control.
Help me.
Thanks a lot!
|
|
|
|
|
You have to add it to the ToolBox yourself. Just adding a reference to the .OCX won't do it. Right-click inside the Toolbox and pick Add/Remove Items... I think you can figure it out from there.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
need help... how to integrate some data of the application-1 to be used or display to the other application-2....
Thank
|
|
|
|
|
Would you care to elaborate on this?? It doesn't tell us anything about what you're really trying to do or what you're even thinking of doing.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Don't cross post You asked this same question in the SQL forum.
|
|
|
|
|
Hey everyone,
I've been looking around for some advice on OpenGL with VB.NET. I spent the last year learning and refining my ability with VB.NET and want to move into the 3D world.
I have 2 questions:
1. Would it be better for me to pickup C++ again to program this in or is there not too big of a differece? At what point (if any) is the difference noticeable?
2. I've pretty much only see "Tao" and "CsGL" as ways to use OpenGL. Any recommendations/alternatives?
I want to essentially program a simple "game" where you login, it shows you a sprite of some kind, you can move around and interact with objects, etc. Long term, if I can make a real game out of it... great. Other than that, just doing it for the experience.
Thanks,
Mike
Gaming at the GuildofBlades.com is the only way to really experiece the level 99 Soul-Sucking Sword!
|
|
|
|
|
Have you reviewed this article? It talks about using CsGL in VB.NET.
Best,
Jun
|
|
|
|
|
I'm working on an applicaiotn that distributes files -- as they come into one directory, the file name is parsed, and the file is moved to the appropriate output directory based on the name.
I have it working well for the case where a file in the monitored directory is changed, or copied in from a local location.
I have two issues I'm having a problem coding for:
1) If the program starts and there are already files in the directory, I want it to work through the file list one at a time and process the files appropriately.
2) Sometimes the file is transferred in via FTP so it fires multiple change notifications. I want to ignore them until the transfer is done.
Thanks in advance for any help you can give!
best,
Scott
|
|
|
|
|
STemaat wrote: If the program starts and there are already files in the directory, I want it to work through the file list one at a time and process the files appropriately.
OK, what's the big deal? Use the Directory class and it's GetFiles method to get a list of files in the directory and start feeding them to whatever routine you've written to process the files.
STemaat wrote: Sometimes the file is transferred in via FTP so it fires multiple change notifications. I want to ignore them until the transfer is done.
There is no Closed notification in the FileSystemWatcher. It's impossible for it to know when another application is completely finished with a file before it notifies you. You're only workaround is to, every so often, try and open the file with exclusive rights (DenyShareRead and DenyShareWrite). Once the file successfully opens, you've got a pretty good indicator of whether or not the file is done being written by the FTP server. This, of course, depends entirely on the functionality of the FTP Server that you're using and how it writes to files as they're being uploaded.
Dave Kreskowiak
Microsoft MVP - Visual Basic
-- modified at 14:52 Monday 26th June, 2006
|
|
|
|
|
>>>OK, what's the big deal? Use the Directory class and it's GetFiles method to get a list of files in the directory and start feeding them to whatever routine you've written to process the files.
Hmm...someone here is a NOOB (namely me)
>>>You're only workaround is to, every so often, try and open the file with exclusive rights (DenyShareRead and DenyShareWrite).
Okay, think I can handle that.
Thanks.
|
|
|
|
|
STemaat wrote: >>>OK, what's the big deal? Use the Directory class and it's GetFiles method to get a list of files in the directory and start feeding them to whatever routine you've written to process the files.
Hmm...someone here is a NOOB (namely me)
You never said what part of that you were having a problem with...
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Really what I was hoping for was a code snippet in both cases. I am having a hard time finding examples I can wrap my mind around/adapt, and neither topic is covered well in the textbook for the class I took last semester.
I think I'm getting my mind warapped around the first one...my thought is to simply "touch" every file that happens to be in the directory, which would fire the changed event of the watcher.
First concept that comes to mind on the second issue is putting the file open into an Until loop.
Am I on the right track?
|
|
|
|
|
STemaat wrote: I think I'm getting my mind warapped around the first one...my thought is to simply "touch" every file that happens to be in the directory, which would fire the changed event of the watcher.
You could do that, but the FileSystemWatcher has been known to miss events now and then when firing alot of them all at once. "Touching" the files involves extra work you don't have to do. Just get the list of files and pass each one to the routine that does the processing. The event handler for the FSW should be doing the same thing.
STemaat wrote: First concept that comes to mind on the second issue is putting the file open into an Until loop.
Yep. All you have to do is put the thread to sleep for a little while, maybe one second, inside the loop if the Open fails. That way you're not bogging down the system.
Dim attempting As Boolean = True
While attempting
Try
' Open the file for exclusive read/write
' close it
' pass the filename to some method to do the actual processing
attempting = False
Catch
Thread.Sleep(1000)
End Try
End While
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|