简体   繁体   中英

How to implement async file download in C# ActiveX

I'm doing a reimplementation of a C++ ActiveX control in C#.

The C++ Version uses a property class which inherits from CDataPathProperty. How should the following code look in C#?

class CFileProperty : public CDataPathProperty
{
 DECLARE_DYNAMIC(CFileProperty )
    ...
}

Any references appreciated.

What I'm actually trying to do is: The ActiveX is hosted in IE, inside an object tag:

<object type="application/content-type" data="path-or-url-to-file">
    <PARAM name="Url" value="path-or-url-to-file" />
</object>

So IE should download the file itself and provide it to the ActiveX. I must ensure that the file is not downloaded twice! Of course I would appreciate a solution, where the data parameter is used and the url parameter is obsolete.

I couldn't find a CDataPathProperty conterpart in C#. So I was looking for an alternative approach.

In order to handle the object tag with content type and data attributes correctly one can implement IPersitMoniker. The only relevant method is Load.

 public void Load(int fFullyAvailable, IMoniker pmk, IBindCtx pbc, uint grfMode)
 {
     if (pmk == null)
         throw new ArgumentNullException("pmk");

     string url;
     pmk.GetDisplayName(null, null, out url);

     // Use the moniker to download the persisted data
     // and obtain an IStream on that data
     Guid iid = InterfaceID.IID_IStream;
     object pStream;
     pmk.BindToStorage(pbc, null, ref iid, out pStream);

     // do whatever you want with the data inside pStream
     ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM