-1

I'm pretty new to C# (Only about a month of experience). I'm working on a project that will get the URL address from a .url file but I have no idea how to go about doing so.

I've tried googling but I keep getting "text to url", not the other way around. Any help would be awesome! Thanks for any input in advance! I'm also new to the site, so if need to answer more questions, please let me know!

Edit: Basically, I'm trying to convert all the internet shortcuts in my favorites folders into their addresses. So for example, turn my "Google" shortcut into http://www.google.com. I hope that helped.

Piccolo0
  • 23
  • 3
  • 2
    So no research? http://stackoverflow.com/questions/6434126/how-to-access-url-and-bookmark-title-in-url-files – Rick S Oct 07 '14 at 17:52
  • 2
    What's a `.url` file? Is its contents just text? If so then you'd likely just read in the file contents into a string (or array of strings?) and parse the value you're looking for from that. There may already be a tool somewhere to do that (I'm not aware of one). If there isn't, then it would be pretty cool for you to write that tool (I imagine it would be a single class with not much code in it) and publish it on NuGet for others to use. – David Oct 07 '14 at 17:55

1 Answers1

1

Will be quite easy I think, just try something like:

string line = File.ReadLines(FileName).Skip(1).Take(1).First();
string url = line.Replace("URL=","");
url = url.Replace("\"","");
url = url.Replace("BASE","");

Kind of ugly but it works, I will advise using Regular Expressions to validate the resulting URL.

Sameer Shemna
  • 886
  • 10
  • 19
  • Yes, this code did what I needed for my project. Thank you! I did have to add an extra line to replace the word BASE from coming up on my links (just in case anyone else has the same problem). – Piccolo0 Oct 07 '14 at 19:45