Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8785105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:16:07+00:00 2026-06-13T21:16:07+00:00

I have a task to write an object that can receive a different type

  • 0

I have a task to write an object that can receive a different type of paths/urls, and return what type of path/url it is. For example the path can be

1. [drive]:\Temp 
2. \\Temp 
3. Temp (assuming that it relative Temp), 
4. /Temp 
5. ~/Temp 
6. file://[drive]:/Temp 
7. file://Temp 
8. [scheme]://something/Temp

…and so on.

How I can check in C# if it’s physical path, relative url, or absolute url?

I think it’s relatively easy to know if it’s relative or absolute uri, but how to know if it’s UNC path?

I tried to use Uri object and it’s IsUnc property, but it not really helps me….for c:\temp it returns false, for “/temp”, “temp/” and “temp” it throws an exception that format is incorrect. Does exists any built in object in .NET 3.5 that can help me with this, or what algorithm i can use to determine the type of path?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:16:08+00:00Added an answer on June 13, 2026 at 9:16 pm

    Try this:

    var paths = new[]
    {
       @"C:\Temp",
       @"\\Temp",
       "Temp",
       "/Temp",
       "~/Temp",
       "file://C:/Temp",
       "file://Temp",
       "http://something/Temp"
    };
    
    foreach (string p in paths)
    {
       Uri uri;
       if (!Uri.TryCreate(p, UriKind.RelativeOrAbsolute, out uri))
       {
          Console.WriteLine("'{0}' is not a valid URI", p);
       }
       else if (!uri.IsAbsoluteUri)
       {
          Console.WriteLine("'{0}' is a relative URI", p);
       }
       else if (uri.IsFile)
       {
          if (uri.IsUnc)
          {
             Console.WriteLine("'{0}' is a UNC path", p);
          }
          else
          {
             Console.WriteLine("'{0}' is a file URI", p);
          }
       }
       else
       {
          Console.WriteLine("'{0}' is an absolute URI", p);
       }
    }
    

    Output:

    ‘C:\Temp’ is a file URI
    ‘\\Temp’ is a UNC path
    ‘Temp’ is a relative URI
    ‘/Temp’ is a relative URI
    ‘~/Temp’ is a relative URI
    ‘file://C:/Temp’ is a file URI
    ‘file://Temp’ is a UNC path
    ‘http://something/Temp’ is an absolute URI

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been assigned wit the task to write a program that takes a
I have a task where i need to write a multidimensional array to HDFS.
I have question about XSLT1.0. The task is to write out in HTML all
I have very little knowledge about unix. My task is to write a shell
i have task which takes a parameter and has three modes of results Example
I have task involving reading SAS .xpt files using .NET. For that I'm using
I have some task regarding do operations on database using ADODB in Vb.NET. Can
I have a task to do, I need to take data that has been
I'm making a task-based program that needs to have plugins. Tasks need to have
I have an issue that I feel many programmers can relate to... I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.