4 Replies - 506 Views - Last Post: 09 January 2016 - 12:40 PM Rate Topic: -----

#1 Jokuk55   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 13-February 15

Slash in a filename(filepath)

Posted 09 January 2016 - 09:41 AM

I want to download a html file with its address as a filename. When I use "/" in a filename I get an exception "An unhandled exception of type 'System.Net.WebException' occured in System.dll'

string httpAddress = @"http://google.com";

using(WebClient client = new WebClient())
{
   client.DownloadFile(httpAddress, @"C:\temp\files\" + @httpAddress + ".html);
}



Is This A Good Question/Topic? 0
  • +

Replies To: Slash in a filename(filepath)

#2 Atli   User is offline

  • Enhance Your Calm
  • member icon

Reputation: 4241
  • View blog
  • Posts: 7,216
  • Joined: 08-June 10

Re: Slash in a filename(filepath)

Posted 09 January 2016 - 10:20 AM

First, you have a syntax error at the end of line 5; missing closing double-quote.

Second, consider how the path this code creates will look like:
C:\temp\files\http://google.com.html


That's completely invalid.
At the very least, you need to strip the protocol (the "http://") off the URL.
Was This Post Helpful? 0
  • +
  • -

#3 Jokuk55   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 13-February 15

Re: Slash in a filename(filepath)

Posted 09 January 2016 - 11:39 AM

Sry I rewrited it by hand (can't use copy-paste because I am using Visual Studio in a virtual machine and shared clipboard doesn't work). Is there any way to have a slash in a filename so I could save a file with a name like "www.examplelink/index.html" or "www.examplelink/file.txt"?
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is offline

  • palpable absurdity
  • member icon

Reputation: 6912
  • View blog
  • Posts: 28,592
  • Joined: 12-December 12

Re: Slash in a filename(filepath)

Posted 09 January 2016 - 11:48 AM

Try it. If you go into File Explorer in Windows and try to name a file with a forward-slash Windows simply discards the character with a warning message.
Was This Post Helpful? 1
  • +
  • -

#5 Jokuk55   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 13-February 15

Re: Slash in a filename(filepath)

Posted 09 January 2016 - 12:40 PM

Oh lol, I thought it is only true for backslash, not slash.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1