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

Getting the underlying filename of a System.IO.StreamWriter

I am handed a reference to a StreamWriter object. I need to obtain the name
of the underlying file name that this writer is associated with. I can't
find a method to do so - am I missing something?

Thanks,
Yom
Nov 16 '05 #1
2 4081
The BaseStream property of the StreamWriter will give you a reference to the
stream that is used. If you know for sure this stream is a FileStream
instance, you can cast it to that type, and use the Name property the get
the file's name. (according to the docs this is the "name passed to the
constructor" - might be a relative path!)

Niki

"Tom Jones" <to********@hotmail.com> wrote in
news:%2*****************@TK2MSFTNGP11.phx.gbl...
I am handed a reference to a StreamWriter object. I need to obtain the name of the underlying file name that this writer is associated with. I can't
find a method to do so - am I missing something?

Thanks,
Yom

Nov 16 '05 #2

"Tom Jones" wrote...
I am handed a reference to a StreamWriter object.
I need to obtain the name of the underlying file
name that this writer is associated with. I can't
find a method to do so - am I missing something?


You're missing the fact that the StreamWriter doesn't neccessarily have to
be associated to a *file*. It can be used for any type of Stream. Hence,
there are no file-specific methods or properties for a StreamWriter.

However, if it really *is* associated to a file you could try something
like:

FileStream fs =
(FileStream)
yourStreamWriterObject.BaseStream;

string filename = fs.Name;
// Bjorn A

Nov 16 '05 #3

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

Similar topics

1
by: Trevor | last post by:
Also posted in general ASP.NET forum. System.IO.IOException: The filename, directory name, or volume label syntax is incorrect. I have hit a problem for which I can find no solutions. Has...
1
by: Lars Hansen | last post by:
Hi This is probably pretty basic, but I have a problem with the access-level (local variable), when creating a new StreamWriter. I am trying to write some price information to a textfile - which...
4
by: news.microsoft.com | last post by:
Hello All, im am new to ASP.NET, so bare with me. i have an application that i am building in stages. stage1 user picks data required stage2 file is written to a virutal directory Stage3...
1
by: C.W. | last post by:
I am trying to connect to a remote server in order to perform an http post inside my asp.net page. However, I consistently get the following error: System.Net.Sockets.Socket.Receive(Byte...
4
by: eBob.com | last post by:
I have a "parent" form (if that's the right terminology), Form1. I declare two public values in the parent form : Public Class Form1 Inherits System.Windows.Forms.Form Public CurDir As String =...
3
by: Rahul Anand | last post by:
As per our requirements we have a web service which internally connects (Simple HTTP Post Request) to a remote server to initiate some work. We are calling the web service method asynchronously...
7
by: Jim Butler | last post by:
I have this error that is happening on all of our web servers (production included). It basically started occurring once we loaded 2005 sql client tools, asp.net 2.0 (and all related prerequistes)...
2
by: Andrew Hunot | last post by:
I have VB code in VS2003 which creates a HttpWebRequest and performs a POST operation to a remote URL (an https site), which runs fine and receives a valid response. However exactly the same...
1
by: herbert | last post by:
I am using a TraceSource object configured via app.config. In order to delete the old file before starting the new trace, I need to obtain the filename from the listener. What am I doing wrong in...
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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...
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...
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...

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.