locked
If file excist else open other one RRS feed

  • Question

  • User388131 posted

    I am using this to open a file in google docs in a webview

    Webview.Source = "https://docs.google.com/document/d/1R_veGr31e39d4gJa0CtAdzU5BxDl5ZV-2bssofU8wSU/edit?usp=sharing";

    But when it is not there i want to open another one as backup. When removing the first from google docs it is not opening the second one

    Trying to make a if statement , no luck

    ` if (File.Exists("https://docs.google.com/document/d/1RveGr31e39d4gJa0CtAdzU5BxDl5ZV-2bssofU8wSU/edit?usp=sharing")) { Webview.Source = "https://docs.google.com/document/d/1RveGr31e39d4gJa0CtAdzU5BxDl5ZV-2bssofU8wSU/edit?usp=sharing";

                }
              else
                Webview.Source = "https://docs.google.com/document/d/1JtPBbacWjjE1RnqT7MlliexLFk618iNS5yUBBCkh1bs/edit?usp=sharing";
            {
    
                }
        }`
    
    Friday, November 15, 2019 8:37 PM

All replies

  • User53115 posted

    I don't think the File.Exists() method is valid for URLs, it's supposed to be a path to a local file.

    Friday, November 15, 2019 9:06 PM
  • User388131 posted

    Thanks for the reply JoeManke,

    Think so because this is not working also . It is not opening the document.

    if (File.Exists("https://docs.google.com/document/d/1JtPBbacWjjE1RnqT7MlliexLFk618iNS5yUBBCkh1bs/edit?usp=sharing")) { Webview.Source = "https://docs.google.com/document/d/1JtPBbacWjjE1RnqT7MlliexLFk618iNS5yUBBCkh1bs/edit?usp=sharing";

            } 
    
    Friday, November 15, 2019 9:18 PM
  • User53115 posted

    What do you mean by "not working"? Is that if statement returning true or false? Are you actually reaching the line where you try to set the WebView.Source?

    Friday, November 15, 2019 9:25 PM
  • User388131 posted

    It is not opening the document

    When only using this it is working

    `public Web() { InitializeComponent();

                Webview.Source ="https://docs.google.com/document/d/1JtPBbacWjjE1RnqT7MlliexLFk618iNS5yUBBCkh1bs/edit?usp=sharing";
            }
        }`
    
    Friday, November 15, 2019 9:31 PM
  • User89714 posted

    @Borisoprit

    As @JoeManke said, you should not be using File.Exists

    Instead, use a HTTP "Head" message (or if the URL doesn't support "Head" then use a HTTP "Get" message).

    HttpResponseMessage responseMessage = await httpClient.SendAsync( HttpRequestMessage(HttpMethod.Head, url), HttpCompletionOption.ResponseHeadersRead, cancellationToken); using (responseMessage) { // Check responseMessage.StatusCode here }

    In that code, httpClient is an instance of HttpClient that you re-use rather than creating a new instance each time. The cancellationToken argument is optional.

    Friday, November 15, 2019 10:56 PM
  • User388131 posted

    Thanks for the example ,

    This is new for me i never worked with HttpResponseMessage

    How do i implant this in my Web.xaml.cs to check when start page ?

    Saturday, November 16, 2019 2:53 PM
  • User89714 posted

    @Borisoprit said: Thanks for the example ,

    This is new for me i never worked with HttpResponseMessage

    How do i implant this in my Web.xaml.cs to check when start page ?

    You can find an introduction to using HTTP with Xamarin.Forms at https://docs.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/web-services/rest

    It doesn't cover the Head request, but you can copy the code I posted previously to do that.

    Saturday, November 16, 2019 2:58 PM