extra \ charecter in file path

  • Thread starter Thread starter prakashdehury
  • Start date Start date
P

prakashdehury

In my c# application
when i use this FileStream fs = File.Open("C:\\Temp\\497_01\\\
\Assumption.txt",FileMode.Open);

1. it works fine, when i ran the exe locally. (e.i : c:\> c\temp
\Test.exe)

2. When i execute the exe from share path it throw an exception saying
file does not exists
(e.i :C:\> \\TTTYUOT\temp\Test.exe)

Can any one suggest what could be the reason?


thanks
Kumar
 
In my c# application
when i use this FileStream fs = File.Open("C:\\Temp\\497_01\\\
\Assumption.txt",FileMode.Open);

1. it works fine, when i ran the exe locally. (e.i : c:\> c\temp
\Test.exe)

2. When i execute the exe from share path it throw an exception saying
file does not exists
(e.i :C:\> \\TTTYUOT\temp\Test.exe)

Can any one suggest what could be the reason?

thanks
Kumar

Hi,

Can you add more code sample? I still can't get the connection between
the FileStream and the exception.

Moty
 
Hi Moty,

The problem is with this line only
File.Open("C:\\Temp\\497_01\\\\Assumption.txt",FileMode.Open);

the extra "\\" between present in the file path "497_01\\\
\Assumption".

it runs fine when i execute the code locally but throws exception file
not found when i ran it through network share like :C:\> \\TTTYUOT\temp
\Test.exe)


thanks
Kumar
 
In my c# application
when i use this FileStream fs = File.Open("C:\\Temp\\497_01\\\
\Assumption.txt",FileMode.Open);

First one hint. For file path it's better to use verbatim strings:
.... @"C:\Temp\497_01\\Asumption.txt" ...
this is much easier to read.
1. it works fine, when i ran the exe locally. (e.i : c:\> c\temp
\Test.exe)

This puzzles me. I couldn't even construct such path.
What Filesystem you are using.
2. When i execute the exe from share path it throw an exception saying
file does not exists
(e.i :C:\> \\TTTYUOT\temp\Test.exe)

The extra slash seems to have an effect like a relative path.
Where is the file actually located ?
 
First one hint. For file path it's better to use verbatim strings:
... @"C:\Temp\497_01\\Asumption.txt" ...
this is much easier to read.




This puzzles me. I couldn't even construct such path.
What Filesystem you are using.




The extra slash seems to have an effect like a relative path.
Where is the file actually located ?


The file is located at C:\Temp\497_01\Assumption.txtI understand the the path is not correct but it works in local mode
but not in network mode (i.e C:\> \\TTTYUOT\temp\Test.exe)
 
The .Net permissions are different when you run the executable locally
than when you run it from a share path. The default permissions of a .Net
executabe loaded from a share path do not allow you to perform file IO
operations. You can chage those permissions from the .Net administration
tool in the control panel.
 
The file is located at C:\Temp\497_01\Assumption.txt
I understand the the path is not correct but it works in local mode
but not in network mode (i.e C:\> \\TTTYUOT\temp\Test.exe)

So, why you don't simply remove the extra slash?

Christof
 
The .Net permissions are different when you run the executable locally
than when you run it from a share path. The default permissions of a .Net
executabe loaded from a share path do not allow you to perform file IO
operations. You can chage those permissions from the .Net administration
tool in the control panel.


Thanks so much it was a .Net security/permissions issue its is fixed
after adding File IO. to the Zone
 
Back
Top