473,561 Members | 3,852 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Streamwriter Path

Rob
I have a streamwriter that may get closed. The writer is passed into another
class by ref and is consumed there. What can happen is that the writer might
get closed by the spawning class.

Is there a way to extract the path of the streamwriter passed in by ref? I
don't see a property for it, but there might be a work around someone has.

Let me know!

Thanks!

Rob
Jan 3 '06 #1
3 2977
Rob <Ro*@discussion s.microsoft.com > wrote:
I have a streamwriter that may get closed. The writer is passed into another
class by ref and is consumed there. What can happen is that the writer might
get closed by the spawning class.

Is there a way to extract the path of the streamwriter passed in by ref? I
don't see a property for it, but there might be a work around someone has.


No, because there may not *be* a path. (What would the StreamWriter for
a writer to a MemoryStream be?)

What you *can* do is use the StreamWriter.Ba seStream to get the
underlying stream, and then if that's a FileStream you can use
FileStream.Name to access the path.

I'm not sure why you've mentioned twice that the StreamWriter is being
passed by reference - it's irrelevant here, even if it's true. I
*suspect* that it's not actually being passed by reference, however -
or at least doesn't need to be. It's worth understanding parameter
passing thoroughly. See
http://www.pobox.com/~skeet/csharp/parameters.html for more
information.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 3 '06 #2
Rob
Thanks Jon,

That is what I ended up doing. To clairfy, the ref to the streamwriter was
to originally use an already open writer from the spawning app. A new tread
for a seporate class is later launched and the writer is passed by ref to the
that class.

Now I am just closing the writer, then opening it using the path of the
filestream that was passed in.

Simply put - _jobLogPath =
((System.IO.Fil eStream)(((Syst em.IO.Stream)(_ JobLog.BaseStre am)))).Name;

"Jon Skeet [C# MVP]" wrote:
Rob <Ro*@discussion s.microsoft.com > wrote:
I have a streamwriter that may get closed. The writer is passed into another
class by ref and is consumed there. What can happen is that the writer might
get closed by the spawning class.

Is there a way to extract the path of the streamwriter passed in by ref? I
don't see a property for it, but there might be a work around someone has.


No, because there may not *be* a path. (What would the StreamWriter for
a writer to a MemoryStream be?)

What you *can* do is use the StreamWriter.Ba seStream to get the
underlying stream, and then if that's a FileStream you can use
FileStream.Name to access the path.

I'm not sure why you've mentioned twice that the StreamWriter is being
passed by reference - it's irrelevant here, even if it's true. I
*suspect* that it's not actually being passed by reference, however -
or at least doesn't need to be. It's worth understanding parameter
passing thoroughly. See
http://www.pobox.com/~skeet/csharp/parameters.html for more
information.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Jan 3 '06 #3
Rob <Ro*@discussion s.microsoft.com > wrote:
That is what I ended up doing. To clairfy, the ref to the streamwriter was
to originally use an already open writer from the spawning app. A new tread
for a seporate class is later launched and the writer is passed by ref to the
that class.
That still doesn't explain why you need to pass by reference. Did you
read the link I posted?
Now I am just closing the writer, then opening it using the path of the
filestream that was passed in.

Simply put - _jobLogPath =
((System.IO.Fil eStream)(((Syst em.IO.Stream)

(_JobLog.BaseSt ream)))).Name;

Right. You don't need to cast to Stream, by the way - BaseStream is
already declared to return a Stream.
--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 3 '06 #4

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

Similar topics

2
2414
by: Joecx | last post by:
Using vb.net, I am using Streamreader to read a text file and searching for a line to delete, the I close the file and open it as a streamwriter so I can put the new file back to disk without the line that I deleted. Can someone tell me how I can do this without having to close the file first before switching to streamwriter, because closing...
2
2926
by: Daniel | last post by:
if System.IO.StreamWriter write throws an exception, is there anyway to close the System.IO.StreamWriter object? it seems to stay open when this happens then future attempts to write to that same path fail because it says its in use by another process.
5
18866
by: Brendan Miller | last post by:
Hi, I have been having a problem writing the contents of a dataset to a .csv file. When I write to a .csv file and open it with either Excel or Wordpad the "french" characters are wrong. When I open the file with notepad the characters are displayed correctly. e.g. in notepad: École, in Wordpad/Excel: Ã?cole. Having the user import a...
4
20546
by: rex64 | last post by:
I am getting an error message and I have not been able to figure hot how to fix it. I have done some research with no answers yet. I found this code that may help? Not sure what to do with it. using (StreamWriter sw = new StreamWriter (fullAddress , false, Encoding.UTF7)) Error message::::::::::::::::::::::::::::::::::::::::::::::
2
2069
by: David Buchan | last post by:
I have written a program to write some text to a file. Currently, if the file already exists, the program simply overwrites it. What I'd like to do, is have the program ask me if I wish to overwrite the existing file, ask for a new name if the answer is no, or overwrite if the answer is yes. I have the line: Dim objWriter As...
6
10204
by: Don | last post by:
I'm having problems working with a streamwriter object. After closing the streamwriter and setting it to Nothing, I try to delete the file it was writing to, but I always get the following error message: "The process cannot access the file "whatever" because it is being used by another process." I've even tried opening another file using...
7
9769
by: Eran.Yasso | last post by:
Hi, In the MSDN the sample doesn't use the close() method. But I know that in most languages you do need to use the close() method after reading and writing to a file. from MSDN: public static void Main() {
3
9190
by: BLUE | last post by:
I've created a folder named TestDir in my wwwroot and I've created the associated virtual application from IIS management snap-in. I've given full control to TestDir to: IUSR, ASPNET, Network service, Anonimous access, Everyone, Users, VS Developers I've set write access and low application protection from IIS management snap-in.
5
3002
by: BLUE | last post by:
I insert a string in cache in a property set and I retrieve that string in the get. I retrieve my string with Read web method and I insert it with Write web method: to try cache I do Read, Write, Read. When I do the second Read, string is null if in the property set, before/after inserting data into cache I write this code: using...
0
7639
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
7855
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
8074
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
7608
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...
0
7926
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6198
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3594
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2058
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
0
885
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.