473,385 Members | 1,593 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,385 software developers and data experts.

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 2957
Rob <Ro*@discussions.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.BaseStream 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.com>
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.FileStream)(((System.IO.Stream)(_JobLo g.BaseStream)))).Name;

"Jon Skeet [C# MVP]" wrote:
Rob <Ro*@discussions.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.BaseStream 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.com>
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*@discussions.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.FileStream)(((System.IO.Stream)

(_JobLog.BaseStream)))).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.com>
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
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...
2
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...
5
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...
4
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....
2
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...
6
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...
7
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...
3
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...
5
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,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.