473,569 Members | 2,731 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(vpat h+myFileName, FileMode.Create New);
fstream.Write(m yFileBytes, 0, myFileSize);
fstream.Close() ;

Where vpath = "\\MyServer\MyD ir\";

And myFileName is an XML file name.

The file ends up in "C:\MyServer\My Dir\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 8082
Don,
>Where vpath = "\\MyServer\MyD ir\";
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\My Dir\";
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\MyD ir\";

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\My Dir\";
Mattias
vpath is set from parameters in a config file. "\\MyServer\MyD ir\" is
what is in the config file. When I step thru the code and view vpath
while running it appears as "\\MyServer\MyD ir\", 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\myDi r\". 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\my Dir\"?

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\my Dir\"?
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**********@n ospam.acs-inc.comwrote in message
news:xn******** *******@news.mi crosoft.com...
Problem solved:

The config file accidently had a space in front of the file path so it
was actually " \\myServer\myDi r\". 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\my Dir\"?

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\my Dir\"?

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\mydi r\"
to "c:\myserver\my dir\". 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
7175
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 created if they don't already exist, and if the drive happens to be one a folder cannot be created on (ie a cdrom drive) it would just be skipped...
9
5839
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 working with the StreamReader object I got a deadlock when I tried reading the file while my external application was writing to it. So far I am able...
3
4496
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 mapped drive: M:\ And at this browser URL: http://mrs2/P2M/login.aspx I expected MapPath to map a path on the server where the application's
0
386
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 a .NET web app and looks like this: FileStream fs = new FileStream(_documentInfo.DocFile, FileMode.Open, FileAccess.Read); This statement...
9
2150
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 sample: Dim fs1 As New System.IO.FileStream("C:\Test.txt", IO.FileMode.OpenOrCreate, IO.FileAccess.ReadWrite, IO.FileShare.Read) '... 'This is...
2
2663
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 server where the network drive exists. Although of this check I am sometimes getting an exception (in 5% of times)saying "Could not find the...
7
2292
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, the other in which I close the FileStream afterwards, although both return the same error. Here are the two versions of the code and the errors they...
6
2165
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 and/or processes so that multiple threads/processes can write to the same file (all threads use the same instance of the stream, processes use a...
3
10055
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 and not have to store the file? If anyone has a solution to getting the UNC path I would love it. Please.
0
7698
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8122
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7673
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.