【问题标题】:C# webbrowser not showing updated resultC# webbrowser 不显示更新的结果
【发布时间】:2012-10-27 13:02:33
【问题描述】:

我在使用 webbrowser 时遇到问题,或者可能是 ftp。我正在上传一张图片,当我浏览网络浏览器时,它会向我显示旧照片,但我上传的图片会到达 ftp 并被覆盖。代码如下:

 webBrowser1.Refresh(WebBrowserRefreshOption.Completely);
        webBrowser1.Navigate("www.google.com");
        openFileDialog1.ShowDialog();
        string filename = Path.GetFullPath(openFileDialog1.FileName);
        
        FileInfo toUpload = new FileInfo(@"upload.jpg");
        FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://fingercube.co.cc/public_html/objimg/" + toUpload.Name);
        request.Method = WebRequestMethods.Ftp.UploadFile;
        request.Credentials = new NetworkCredential("username", "pass");
        Stream ftpStream = request.GetRequestStream();
        FileStream file = File.OpenRead(filename);
        int lenght = 2;
        byte[] buffer = new byte[lenght];
        int bytesRead = 0;
        do
        {
            bytesRead = file.Read(buffer, 0, lenght);
            ftpStream.Write(buffer, 0, bytesRead);
        }

        while (bytesRead != 0);
        file.Close();
        ftpStream.Close();

        
       webBrowser1.Navigate("http://fingercube.co.cc/objimg/"+toUpload.Name);

它每次都向我显示旧照片,但每次都上传照片。 :(

【问题讨论】:

    标签: c# browser ftpwebrequest


    【解决方案1】:

    如果缓存建议不起作用,请尝试执行以下操作。

    this.webBrowser1.Navigate("about:blank");
    HtmlDocument doc = this.wbbFinalise.Document;
    doc.Write(string.Empty);
    

    然后导航到您的 ftp 位置。

    我在尝试在 Web 浏览器中刷新本地生成的 HTTP 页面时遇到了类似的问题,这解决了问题。

    【讨论】:

    • HtmlDocument doc = this.wbbFinalise.Document;这是什么 wbbFinalise ?我遇到了麻烦!
    【解决方案2】:

    图像被缓存到 IE 缓存中。您必须在刷新控件之前清除缓存。看看这里:http://www.gutgames.com/post/Clearing-the-Cache-of-a-WebBrowser-Control.aspx

    另外,关于 SO 的相关问题:WebBrowser control caching issue

    【讨论】:

      【解决方案3】:

      得到了解决方案..问题在于缓存简单的解决方案是每次都发出新请求。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-03-18
        • 1970-01-01
        • 2021-12-24
        • 1970-01-01
        • 1970-01-01
        • 2011-09-09
        相关资源
        最近更新 更多