473,387 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

FileStream writes to C drive instead of UNC path given

The following writes to my C drive instead of the server\path given:

fstream = new FileStream(vpath+myFileName, FileMode.CreateNew);
fstream.Write(myFileBytes, 0, myFileSize);
fstream.Close();

Where vpath = "\\MyServer\MyDir\";

And myFileName is an XML file name.

The file ends up in "C:\MyServer\MyDir\myFileName.xml".

Why is it doing this? Yes, I have writes to the server. I can copy to
it using windows explorer.

..NET 1.1, C#.
--

Don Gollahon
Feb 22 '07 #1
5 8070
Don,
>Where vpath = "\\MyServer\MyDir\";
Is that your actual asseignment code? It shouldn't even compile. Keep
in mind that \ is an escape character is C#. You need

vpath = "\\\\MyServer\\MyDir\\";

or

vpath = @"\\MyServer\MyDir\";
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Feb 22 '07 #2
Mattias Sjögren wrote:
Don,
Where vpath = "\\MyServer\MyDir\";

Is that your actual asseignment code? It shouldn't even compile. Keep
in mind that \ is an escape character is C#. You need

vpath = "\\\\MyServer\\MyDir\\";

or

vpath = @"\\MyServer\MyDir\";
Mattias
vpath is set from parameters in a config file. "\\MyServer\MyDir\" is
what is in the config file. When I step thru the code and view vpath
while running it appears as "\\MyServer\MyDir\", too.

--

Don Gollahon
Feb 22 '07 #3
Problem solved:

The config file accidently had a space in front of the file path so it
was actually " \\myServer\myDir\". I removed the space and it works
fine.

Could someone tell me why FileStream did not give an invalid path
error? And why did it convert the path to "C:\myServer\myDir\"?

Is this fixed in a later version of .NET?

Thanks.

--

Don Gollahon
Feb 22 '07 #4
Could someone tell me why FileStream did not give an invalid path
error? And why did it convert the path to "C:\myServer\myDir\"?
Since the path was not a valid UNC path, the path was instead interpreted
as a "relative path". A "relative path" is a valid path.
Is this fixed in a later version of .NET?
It does not need to be fixed. The method gave you the expected result per
the written MSDN documentation.

"Don Gollahon" <do**********@nospam.acs-inc.comwrote in message
news:xn***************@news.microsoft.com...
Problem solved:

The config file accidently had a space in front of the file path so it
was actually " \\myServer\myDir\". I removed the space and it works
fine.

Could someone tell me why FileStream did not give an invalid path
error? And why did it convert the path to "C:\myServer\myDir\"?

Is this fixed in a later version of .NET?

Thanks.

--

Don Gollahon

Feb 25 '07 #5
Michael Phillips, Jr. wrote:
Could someone tell me why FileStream did not give an invalid path
error? And why did it convert the path to "C:\myServer\myDir\"?

Since the path was not a valid UNC path, the path was instead
interpreted as a "relative path". A "relative path" is a valid path.
Is this fixed in a later version of .NET?

It does not need to be fixed. The method gave you the expected
result per the written MSDN documentation.
Whenever two backslashes are together in a relative path it is an
error. This should not have been converted from " \\myserver\mydir\"
to "c:\myserver\mydir\". I would rather it just tell me there was in
invalid path. I've seen other compilers do this, too, now that I think
about it. Like Delphi for Win32 where I have accidently included "\\"
instead of just "\" somewhere in the path. But it invariably still
raises problems later on so I just wish it would throw an appropriate
exception.
--

Don Gollahon
Mar 1 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: jenny | last post by:
Hi, I am trying to find a VB way that would create a folder on all existing drives - the folder name would be the same on each drive. ie c:\backup, d:\backup, etc. But the folders would only be...
9
by: Tom | last post by:
I am working with the this object as oppose to the StreamReader object becuase I need to access a file (to find the contents) while an external application is updating the file. When I was...
3
by: Jon | last post by:
I'm calling Server.MapPath from global.asa through this line of code: Application("reports_dir") = Server.MapPath("Reports") The web application opens on a testing web server (not mine) at this...
0
by: JeffW | last post by:
Researched this, but none of the proposed solutions are working for me. Am hoping for some insight. Am trying to open a binary file that exists on a shared drive for reading. Code lives inside...
9
by: ljlevend | last post by:
I have two questions related to FileStreams. 1. Is there any way to determine whether a file has the permissions that are required by a FileStream constructor? For example, given the following...
2
by: .Net Believer | last post by:
I using the routine below to copy file to a network drive for a regular backup process. Before calling this routine I using another function to check the presence of the LAN connection and the...
7
by: Nathan Sokalski | last post by:
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving,...
6
by: bonk | last post by:
I am trying to create a stream that writes text to a file and: - automatically creates a new file once the current file exceeds a certain size - makes it possible to be used by multiple threads...
3
by: wreed | last post by:
Is there a way on a button press to create a browse for a file box and then when they pick a file on a share drive to convert it to a UNC path and that way I would save the unc path into a table...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.