3 Replies - 638 Views - Last Post: 13 September 2016 - 08:29 AM Rate Topic: -----

#1 RustyAMcM   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 192
  • Joined: 21-January 15

Illegal characters in path

Posted 12 September 2016 - 01:38 PM

I am trying to read from a .txt file located on our network however i keep getting the following message and I am not sure as to why

this is the line that throws the error:{"Illegal characters in path."}
var fs = new FileStream(path4, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);


this is the line that holds the path:

string path4 = (@"\\xxxx-xx-xxx\xxx\xxx\Processed\AFTERHOURS_FEE" + "*" + ".TXT");


the only thing i can think of is it is the wildcard in the path this i need as the file will always start with AFTERHOURS_FEE but the end will be different as it holds the time the file was created here are a few file names from the folder i need to run thru they are all comma deliminated format:

AFTERHOURS_FEE.TXT
AFTERHOURS_FEE020923P.TXT
AFTERHOURS_FEE032151P.TXT

and so on... Any ideas what the problem is? and how to solve this error?

Is This A Good Question/Topic? 0
  • +

Replies To: Illegal characters in path

#2 andrewsw   User is offline

  • palpable absurdity
  • member icon

Reputation: 6905
  • View blog
  • Posts: 28,565
  • Joined: 12-December 12

Re: Illegal characters in path

Posted 12 September 2016 - 01:49 PM

The path should be to a single file, from which a single FileStream will be created. Although wildcards aren't specifically mentioned in the docs, they won't work because the path must identify a single file.

(If the docs don't mention wildcards then assume that you cannot use them.)

You need to use a different method to first locate the file(s) you need, then create a FileStream for whichever one you want.
Was This Post Helpful? 1
  • +
  • -

#3 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7457
  • View blog
  • Posts: 25,100
  • Joined: 05-May 12

Re: Illegal characters in path

Posted 12 September 2016 - 01:50 PM

Your analysis is correct. You cannot open a file with a wildcard in the filename.

Use the DirectoryInfo or Directory classes to resolve the wildcard and get explicit filenames.
Was This Post Helpful? 2
  • +
  • -

#4 RustyAMcM   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 192
  • Joined: 21-January 15

Re: Illegal characters in path

Posted 13 September 2016 - 08:29 AM

andrewsw, skydiver,

Thanks I thought that to be the case would be so much easier if you could do it this way however thanks for the info i will do this another way.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1