I think you are looking for
swOutput.BaseStream.Position
see MSDN: http://msdn.microsoft.com/en-us/library/system.io.stream.position.aspx .
Question
Is there a C# equivalent for StreamWriter of the C++ ostream::tellp? I am porting over some old C++ code to C#, but the client still wants to keep using diskettes (read: old equipment), so I need to find a way to find the file pointer position or to find how much I've written to disk already.
Below is the method that I've created so far:
private bool isDisketteBoundary(ref StreamWriter swOutput, int nCurrentDisketteNo) {
// Get current file pointer position
// long filePosition = nOStream.tellp(); <-- C++ code
long filePosition = 0; // <-- needs to change to find file pointer position
// Valid?
if(filePosition != -1) {
// Is the new size over a boundary?
float numDiskettes = (float)((float)filePosition / (float)Constants.DisketteSize);
int disketteCount = Convert.ToInt32(Math.Ceiling(numDiskettes));
// Is the diskette count larger than the current index?
return (nCurrentDisketteNo < disketteCount) ? true : false;
}
else {
throw new Exception("Unable to get file pointer from StreamWriter");
}
}
Solution
I think you are looking for
swOutput.BaseStream.Position
see MSDN: http://msdn.microsoft.com/en-us/library/system.io.stream.position.aspx .