3

I have trouble with webbrowser or may be ftp. I am uploading a picture and when I navigate the webbrowser it shows me the old photo, yet the picture im uploading gets to the ftp and gets overwrite. Here is the code:

 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);

It shows me the old photo everytime, but the photo is uploaded every time. :(

peterh
  • 11,875
  • 18
  • 85
  • 108
Mohsin Mushtaq
  • 133
  • 1
  • 5
  • 17

3 Answers3

1

If the caching suggestion doesn't work try doing the following.

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

Then navigate to your ftp location.

I had a similar issue while trying to refresh a locally generated HTTP page in the web browser and this fixed the issue.

Bearington
  • 102
  • 2
  • 9
0

The image is cached to IE cache. You must clear the cache before refreshing the control. Have a look here: http://www.gutgames.com/post/Clearing-the-Cache-of-a-WebBrowser-Control.aspx

Also, a related question on SO: WebBrowser control caching issue

Community
  • 1
  • 1
kor_
  • 1,510
  • 1
  • 16
  • 36
-1

got the solution .. the problem was with the cache easy solution to it was to make new request everytime .

Mohsin Mushtaq
  • 133
  • 1
  • 5
  • 17