Feeding PDF through IInternetSession to WebBrowser control - Error

Posted by Codesleuth on Stack Overflow See other posts from Stack Overflow or by Codesleuth
Published on 2010-06-17T14:38:18Z Indexed on 2010/06/18 10:53 UTC
Read the original article Hit count: 304

Filed under:
|
|
|
|

As related to my previous question, I have developed a temporary asynchronous pluggable protocol with the specific aim to be able to serve PDF documents directly to a WebBrowser control via a database.
I need to do this because my limitations include not being able to access the disk other than IsolatedStorage; and a MemoryStream would be far better for serving up PDF documents that average around 31kb.

Unfortunately the code doesn't work, and I'm getting an error from the WebBrowser control (i.e. IE):

Unable to download .

Unable to open this Internet site.  The requested site is either unavailable or cannot be found.  Please try again later.

The line in my code where this occurs is within the following:

pOIProtSink.ReportData(BSCF.BSCF_LASTDATANOTIFICATION, (uint)_stream.Length, (uint)_stream.Length);

However, if you download the project and run it, you will be able to see the stream is successfully read and passed to the browser, so it seems like there's a problem somewhere to do with the end of reading the data:

public uint Read(IntPtr pv, uint cb, out uint pcbRead)
{
    var bytesToRead = Math.Min(cb, _streamBuffer.Length);

    pcbRead = (uint)_stream.Read(_streamBuffer, 0, (int)bytesToRead);
    Marshal.Copy(_streamBuffer, 0, pv, (int)pcbRead);

    return (pcbRead == 0 || pcbRead < cb) ? HRESULT.S_FALSE : HRESULT.S_OK;
}

Here is the entire sample project: InternetSessionSample.zip (VS2010)
I will leave this up for as long as I can to help other people in the future

If anyone has any ideas why I might be getting this message and can shed some light on the problem, I would be grateful for the assistance.

EDIT:

A friend suggested inserting a line that calls the IInternetProtocolSink.ReportProgress with BINDSTATUS_CACHEFILENAMEAVAILABLE pointing at the original file. This prevents it from failing now and shows the PDF in the Adobe Reader control, but means it defeats the purpose of this by having Adobe Reader simply load from the cache file (which I can't provide). See below:

pOIProtSink.ReportProgress(BINDSTATUS.BINDSTATUS_CACHEFILENAMEAVAILABLE,
    @"D:\Visual Studio Solutions\Projects\InternetSessionSample\bin\Debug\sample.pdf");
pOIProtSink.ReportData(BSCF.BSCF_LASTDATANOTIFICATION, (uint)_stream.Length, (uint)_stream.Length);

This is progress though, I guess.

© Stack Overflow or respective owner

Related posts about c#

Related posts about com