Advertisement

07.01.2008 at 04:23AM PDT, ID: 23529713
[x]
Attachment Details

Determine if URI is a link to a file or webpage

Asked by webtubbs in Microsoft Visual Basic.Net, .NET, .NET Framework 2.0

Hi Guys,

I'm trying to put a routine together that can check if a URI is a link to a downloadable file, or a webpage. If it's a webpage, I'd simply launch the default browser to display, but if it's a file, I want to begain a download routine.

I got all excited when I saw the URI.IsFile method, but unfortunately that only checks for "file://". What I want to check for is something like http://www.somewhere.com/somefile.zip (or any other file type that would normally be downloaded, including all MS Office files).

Yes, I do realise a webpage is a file, and obviously I could check the extension against a list of known types, but is there an easier way?

Below is the code I'm using at the moment.

Cheers,

WayneStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
        Dim Exts() As String = {".asp", ".aspx", ".html", ".jsp", ".htm", ".php"}
        Dim ext As String = e.LinkText.Substring(e.LinkText.LastIndexOf("."))
        If Array.IndexOf(Exts, ext) <> -1 Then
            Process.Start(e.LinkText)
        Else
            Dim tmp As String = My.Computer.FileSystem.GetTempFileName & ext
            Dim wc As New Net.WebClient()
            AddHandler wc.DownloadProgressChanged, AddressOf DownloadProgressChanged
            AddHandler wc.DownloadFileCompleted, AddressOf DownloadProgressComplete
            wc.DownloadFileAsync(New Uri(e.LinkText), tmp, tmp)
        End If
[+][-]07.01.2008 at 05:55AM PDT, ID: 21907261

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.01.2008 at 06:10AM PDT, ID: 21907391

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.01.2008 at 09:06AM PDT, ID: 21909043

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.01.2008 at 11:41AM PDT, ID: 21910358

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual Basic.Net, .NET, .NET Framework 2.0
Sign Up Now!
Solution Provided By: martin_kongen
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.01.2008 at 01:50PM PDT, ID: 21911511

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.01.2008 at 02:13PM PDT, ID: 21911699

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.01.2008 at 04:52PM PDT, ID: 21912487

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.02.2008 at 05:40AM PDT, ID: 21915693

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.02.2008 at 09:04PM PDT, ID: 21922608

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.03.2008 at 05:20AM PDT, ID: 21924681

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_EXPERT_20070906