In my program this statement..

FileStream fs = new FileStream(@"C:\SQL.txt" , FileMode.Append, FileAccess.Write);

shows me error...
illegal character in path.
is there in problem in path ...
please quick reply .. thnks ..

kvprajapati commented: Urgen :( Loosing the favor. -1

Recommended Answers

All 9 Replies

Hi,

The line of code works fine. Could you post the code block to research more?

Thanks

Also post the full exception message you receive. When you post your code be sure to use code tags:

[code]

...code here...

[/code]

okay ... i had some mistaken in previous post ...
it was working nicely ...
problem is here ..

string PathName = @"C:\" + FileName;
FileStream fs = new FileStream(PathName , FileMode.Append, FileAccess.Write);

now ...
here .. its showing me error that ... there is some illegal character in path name.
Here FileName is variable which containg the name of file which is passed from another function and i have check that there is no illegal character in that file name of path.

If same path i write without using variable i mean static as shown in my first post , than it is working properly but while dealing with variable it's not working. giving me error.

Error i mean Exception ...

Change your code to this:

string PathName = @"C:\" + FileName;
      Console.WriteLine("Path: '{0}'", PathName);
      FileStream fs = new FileStream(PathName, FileMode.Append, FileAccess.Write);

Look in the "output" window of the Visual Studio IDE and post the line it prints out back to the fourm. You're passing in illegal characters in your file path.

no i m not passing any illegal character ...
and now its solved ...

no i m not passing any illegal character ...
and now its solved ...

i dont think sknake was suggesting you were deliberately using illegal characters, what he asked you to do is a standard step in debugging an error like this; if a variable is throwing an exception, check the contents of the variable at the point of the exception :)

For future reference (and to satisfy my own curiosity), what was causing the issue?

commented: thanks +6

Thanks Ryshad. That is indeed what I was trying to do :)

crazyboy -- Please update us on the cause and solution to your issue. I am curious as well! ;)

Also please mark this thread as solved as you have found a solution to your issue and good luck!

yahhh ...
and i was knowing that sknake told me that for debugging purpose ..
but i have already tried it .
thats y i replied that i m not passing any illegan character ..


and ya solution is ...

the problem was because of null char at the end..
so i just Trim the string ..
and my prob solved ...
:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.