uri

.NET - Get protocol, host, and port

Is there a simple way in .NET to quickly get the current protocol, host, and port? For example, if I'm on the following URL: http://www.mywebsite.com:80/pages/page1.aspx I need to return: http://www.mywebsite.com:80 I know I can use Request.Url.AbsoluteUri to get the complete URL, and I know I can use Request.Url.Authority to get the...

How do I send an email attachment using the designated client, programmatically from Java

I'd like to encourage our users of our RCP application to send the problem details to our support department. To this end, I've added a "Contact support" widget to our standard error dialogue. I've managed to use URI headers to send a stacktrace using Java 6's JDIC call: Desktop.getDesktop().mail(java.net.URI). This will fire up the use...

How to match URIs in text?

How would one go about spotting URIs in a block of text? The idea is to turn such runs of texts into links. This is pretty simple to do if one only considered the http(s) and ftp(s) schemes; however, I am guessing the general problem (considering tel, mailto and other URI schemes) is much more complicated (if it is even possible). I wo...

Determine site's absolute, fully-qualified url in asp.net

How can I consistently get the absolute, fully-qualified root or base url of the site regardless of whether the site is in a virtual directory and regardless of where my code is in the directory structure? I've tried every variable and function I can think of and haven't found a good way. I want to be able to get the url of the current ...

Delphi: OpenFileDialog crashes with URL

Giving a URL to the TOpenFileDialog, the Execute method throws an exception: OpenDialog1.Filename := 'http://www.osfi-bsif.gc.ca/app/DocRepository/1/eng/issues/terrorism/indstld_e.xls'; bResult := OpenDialog1.Execute; But you are allowed to open files from a URL. Delphi 5 ...

What is the benefit of global resource URIs (i.e. addressability)?

What is the benefit of referencing resources using globally-unique URIs (as REST does) versus using a proprietary id format? For example: http://host.com/student/5 http://host.com/student?id=5 In the first approach the entire URL is the ID. In the second approach only the 5 is the ID. What is the practical benefit of the first appro...

What's the difference between a URI and a URL?

People talk about URLs and URIs as if they're different things, but they look the same to the naked eye. What's the difference between the two? ...

Pros and cons of using md5 hash of URI as the primary key in a database

I'm building a database that will store information on a range of objects (such as scientific papers, specimens, DNA sequences, etc.) that all have a presence online and can be identified by a URL, or an identifier such as a DOI. Using these GUIDs as the primary key for the object seems a reasonable idea, and I've followed delicious and ...

C# downloading a webpage. A better way needed, CPU usage high

I'm trying to get this piece of code working a little better. I suspect it's the loop reading one byte at a time. I couldn't find another way of doing this with gzip decompression. Implementing a StreamReader is fine, but it returns a string which I can't pass to the decompression stream. Is there a better way? byte[] bufffer = null; L...

Is there a .NET Framework method for converting file URIs to paths with drive letters?

I was looking for something like Server.MapPath in the ASP.NET realm to convert the output of Assembly.GetExecutingAssembly().CodeBase into a file path with drive letter. The following code works for the test cases I've tried: private static string ConvertUriToPath(string fileName) { fileName = fileName.Replace("file:///", ""); ...

Can I use MediaPlayer to play sounds from a stream? Or, can I use an URI to access a filestream?

I'm using System.Windows.Media.MediaPlayer to play some sounds, and I would like to load these sounds from a ZIP file. It would be nice to be able to load these files as a stream directly from the zip file instead of having to unzip to a temp directory. However, MediaPlayer.open only accepts an URI. So, is there a way to create a URI t...

How to launch a file protocol URL with an anchor from Java?

From a Java program, I need to launch the default browser on a local HTML file, pointed to an anchor inside the file. In Java SE 6, the java.awt.Desktop.browse method will open the file, but will not honor the anchor, so something like the following opens the file at the top, but does not page the browser to the anchor: Desktop.getDesk...

url encoded forward slashes breaking my codeigniter app

i’m trying to create a url string that works like this: /app/process/example.com/index.html so in other words, /app/process/$URL i then retrieve the url with $this->uri->segment(3); the forward slashes in the URL will of course be a problem accessing uri segments, so i’ll go ahead and url encode the URL portion: /app/process/e...

How to map a string to Uri type using the Entity Framework?

My database contains a column of type string, that represents a URL. I'm now wondering how its possible to map this string to a Uri object using the Entity Framework. Any ideas? ...

Method to determine if path string is local or remote machine

What's the best way, using C# or other .NET language, to determine if a file path string is on the local machine or a remote server? It's possible to determine if a path string is UNC using the following: new Uri(path).IsUnc That works great for paths that start with C:\ or other drive letter, but what about paths like: \\machinenam...

Finding a parsing API for partially utf8 encoded URL's

When parsing HTML for certain web pages (most notably, any windows live page) I encounter a lot of URL’s in the following format. http\x3a\x2f\x2fjs.wlxrs.com\x2fjt6xQREgnzkhGufPqwcJjg\x2fempty.htm These appear to be partially UTF8 escaped strings (\x2f = /, \x3a=:, etc …). Is there a .Net API that can be used to transform these strin...

Is there an equivalent of Perl's URI.pm for C# / .NET?

.NET has the Uri class. Perl has its URI module. The major difference is that URI.pm allows you to retrieve the query string components as a hash, and set a hash into the URI to construct a nice URI with query arguments. I don't see anything like that on the .NET side. Is there some hidden class I don't know about? ...

When to use query parameters versus matrix parameters?

Query parameters: http://example.com/apples?order=random&color=blue Matrix parameters: http://example.com/apples;order=random;color=blue When should one use query parameters versus matrix parameters? Why can matrix parameters be used in the middle of a URL but query parameters cannot? For example: http://example.com/apples;order=r...

C#/.NET: Replace host in Uri

What is the nicest way of replacing the host-part of an Uri using .NET? I.e.: string ReplaceHost(string original, string newHostName); //... string s = ReplaceHost("http://oldhostname/index.html", "newhostname"); Assert.AreEqual("http://newhostname/index.html", s); //... string s = ReplaceHost("http://user:pass@oldhostname/index.html",...

Getting the parent name of a URI/URL from absolute name C#

Hello, Given an absolute URI/URL, I want to get a URI/URL which doesn't contain the leaf portion. For example: given http://foo.com/bar/baz.html, I should get http://foo.com/bar/. The code which I could come up with seems a bit lengthy, so I'm wondering if there is a better way. static string GetParentUriString(Uri uri) { ...