views:

10

answers:

1

Hi,

I've got an oob app with a webbrowser on it.

The webbrowser source is databound with a URI defined by me. The URI has a path to a webpage from my server that displays a PDF file from its hardrive.

Note that all this is done on a local network.

URI example: uri = new Uri(@"http://ServerName/ProjectName/PDFViewer.aspx?pdf=somePDF.pdf");

Page code-behind:

    protected void Page_Load(object sender, EventArgs e)

    {

        string myURL = Request.Url.ToString();

        string[] ParamArray = Regex.Split(myURL, "pdf=");

        string Params = ParamArray[ParamArray.Length - 1];

        if (Params.Length > 0)

        {

            Filename = Regex.Replace(Params, @"//", @"\\"); ;

            if (File.Exists(Filename))

            {

                Response.ContentType = "Application/pdf";

                Response.WriteFile(Filename); //Write the file directly to the HTTP content output stream.

                Response.End();

            }

            else

                this.Title = "PDF Not Found";

        }

    }

    protected void Page_Load(object sender, EventArgs e)        {            string myURL = Request.Url.ToString();            string[] ParamArray = Regex.Split(myURL, "pdf=");            //If the URL has parameters, then get them. If not, return a blank string             string Params = ParamArray[ParamArray.Length - 1];            if (Params.Length > 0)            {                //to the called (src) web page                Filename = Regex.Replace(Params, @"//", @"\\"); ;                if (File.Exists(Filename))                {                    Response.ContentType = "Application/pdf";                    Response.WriteFile(Filename); //Write the file directly to the HTTP content output stream.                    Response.End();                }                else                    this.Title = "PDF Not Found";            }        }

The first time I set the WebBrowser source everything it displays the PDF. But when I set the URI one second time the app throws an exception: Trying to revoke a drop target that has not been registered (Exception from HRESULT: 0x80040100).

I've done a few tests and here are the results:

1º new Uri(@"http://ServerName/ProjectName/PDFViewer.aspx?pdf=somePDF.pdf");

2º new Uri(@"http://ServerName/ProjectName/PDFViewer.aspx?pdf=someOtherPDF.pdf"); ->error


1º new Uri(@"http://ServerName/ProjectName/PDFViewer.aspx?pdf=somePDF.pdf");

2º new Uri(@"http://www.google.com"); ->error


1º new Uri(@"http://www.google.com");

2º new Uri(@"http://www.microsoft.com");

2º new Uri(@"http://ServerName/ProjectName/PDFViewer.aspx?pdf=somePDF.pdf");

3º new Uri(@"http://ServerName/ProjectName/PDFViewer.aspx?pdf=someOtherPDF.pdf"); ->error


I also forgot to say that when running the app from my browser (using a HTMLHost) the pages display just fine. Opening the pages using a browser will also work well.

It must be some problem with my aspx page. Any ideas?

Pedro

A: 

I've managed to resolve this by creating a new browser for each page. If you know of a more elegant solution please share.

tekknoplast