Open custom URI which is registered in Windows 8.1 - c#

i like to "open" a (local) customized URI witch is already registered in Windows 8.1.
I can open it, if the Link is embedded in a HTML Mail.
<a href="cobra://goto/addresses/ID=5545">
and it works in Windows Explorer:
cobra://goto/addresses/ID=5545
The ID is sent to the Cobra Application.
I tried to send this URI to the Cobra Application with a WebRequest / FileWebRequest / HttpWebRequest without any Success.
string uriToLaunch = #"cobra://goto/addresses/ID=" + ID;
Uri uri = new Uri(uriToLaunch);
FileWebRequest WebReq = (FileWebRequest)WebRequest.Create(uri);
WebReq.GetResponse();
Error: System.NotSupportedException: "URI prefix is not recognized."
Second try, after I recognized that the URI work with Windows Explorer:
File.Open(uriToLaunch, FileMode.Open);
Error: System.NotSupportedException: "The given path's format is not supported."
Any Suggestions how to do it? I donĀ“t want to build my own URI Parser because Windows knows how to handle it.

you can run a custom URI from C# by calling Process.Start()
eg
System.Diagnostics.Process.Start("uri://here");

The exception is occurring because your uri string is not formatted correctly (you have two prefixes - url: and cobra:)
Try the following:
string uriToLaunch = #"cobra://goto/addresses/ID=" + ID;

Related

C# - Create new URI object to point to a Local file

How can I create a URL object that points to a file that is Local to my web application I thought this would work:
var myURI = new Uri("~/Content/css/pdfX.css");
but I am getting this error:
Invalid URI: The format of the URI could not be determined.
Thanks
You need to convert the virtual path that you have to the corresponding physical file path. You do that with the Server.MapPath method.
var myURI = new Uri(Server.MapPath("~/Content/css/pdfX.css"));

Invalid URL as a Valid URL in C#

how can i add the invalid url (but its valid as it is internal URL) as a valid URL, i am getting an error when i am passing it to System.Uri();
Here is my Uri Code
new System.Uri("mailto:DFO%20ABNS%20Techn/DD-DWA/IND#ADW-NGP", true)
According to this http://www.ietf.org/rfc/rfc6068.txt / should be %-encoded in mailto 'address-part'. .Net will happily take:
new System.Uri("mailto:DFOTechn/DD-DWA/IND#ADW-NGP");
But it is all considered as part of the host.
encoding the '/' characters gives:
new System.Uri("mailto:DFO%20ABNS%20Techn%2FDD-DWA%2FIND#ADW-NGP")
Which .Net correctly parses with ADW-NGP as the host.

How to open a local html file using NavigationWindow when path contains URL fragment?

I am using NavigationWindow to display html files, it worked fine until path does not contain any # or illegal characters.
I just wanted to know is there a way to open html file when the path contains URL fragment, for example: an anchor # like below..
"c:\MyFile.Html#tips"
Currently i am getting the following exception...
Could not find file 'c:\MyFile.Html#tips'
System.Net.WebException was unhandled
HResult=-2146233079
The problem is with the creation of the URI, it seems there is some bug with the URI class.
The URI generated by the following are different,
var filePath = #"c:\MyFile.Html#tips";
var uri = new Uri(filePath);
var uri2 = new Uri("file://" + filePath);
Fragment part of the uri is empty, but uri2 has correct fragment part as "#tips".
The same kind of problem is with the query even after creating URI as uri2, the reported bug for query
string can be found here, Why doesn't System.Uri recognize query parameter for local file path? and Uri class does not parse filesystem URL with query string

C# decodes URL containing %2F on path, is there any way to instruct API to send the URL as it is?

I am having a URL in below format
abcd.com/xyz/pqr%2Fss/abc
I want this to be send to server as it is.
When I build Uri using System.Uri it converts it to abcd.com/xyz/pqr/ss/abc
and it fails as I don't have a URL with the specified path.
When I tried with double encoding
(abcd.com/xyz/pqr%252Fss/abc) it send the Uri as it is but it fails as server side it is converted to (abcd.com/xyz/pqr%2Fss/abc)
If you construct your uri as such:
Uri u = new Uri("http://abcd.com/xyz/pqr%2Fss/abc")
Access the encoded string like this:
u.OriginalString
I had this problem too, but I found the solution: when you use HttpUtility.UrlEncode to be sure that the application will read the url right you have to construct the link this way:
http://www.abcd.com/xyz?val=pqr%2Fss
and not like this
http://www.abcd.com/xyz/pqr%2Fss
where pqr%2Fss is the result of the HttpUtility.UrlEncode("SOME STRING")

Why doesn't FTPWebRequest, or WebRequest in general accept a /../ path?

I am trying to automate some upload/download tasks from an ftp web server. When I connect to the server through client, or through Firefox even, in order to get to my directory, I have to specify a path like this:
ftp://ftpserver.com/../AB00000/incoming/files
If I try to access this:
ftp://ftpserver.com/AB00000/incoming/files
The server throws an error that the directory does not exist. So, the problem:
I am trying to create an FTPWebRequest with the first ftp address, but it always parses out the "/../" part and then my server says the path doesn't exist.
I've tried these:
Uri target = new Uri("ftp://ftpserver.com/../AB00000/incoming/files");
FtpWebRequest request = (FtpWebRequest)WebReqeuest.Create(target);
and
string target = "ftp://ftpserver.com/../AB00000/incoming/files";
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(target);
In the first bit, the path is already incorrect when the Uri object is instantiated, in the second bit, it's after the WebRequest.Create method. Any ideas what's going on?
EDIT:
Additionally, since I posted this, I have tried creating the URI with the no parse option. I have also tried something like this:
string ftpserver = "ftp://ftpserver.com/../";
string path = "12345/01/01/file.toupload";
Uri = new Uri(ftpserver, path, true);
And it always parses out the root part ("/../").
Try escaping the .. with something like:
Uri target = new Uri("ftp://ftpserver.com/%2E%2E/AB00000/incoming/files");
That works according to this blog which I found in this discussion.
Not really sure about it, but it may be for security reasons, since allowing "/../" URIs would potentially let people navigate freely on any server's file system.
Also, the official URI RFC states that when resolving an URI one of the steps performed is actually the removal of "/../" segments, so it's not a problem in the C# library but it's regular URI behavior.
Have you tried using the # symbol like so?
Uri target = new Uri(#"ftp://ftpserver.com/../AB00000/incoming/files");
FtpWebRequest request = (FtpWebRequest)WebReqeuest.Create(target);

Categories