General information
Title:
Reading and writing files in c#
I am working on a conversion to .NET from FoxPro. In Foxpro we had a function called FILETOSTR() which read a file, and did not do any conversion of the file. We also had STRTOFILE() which would take any string and without conversion save it to a file.
Here is what we did with these functions, we could read a Word Doc, or Excel sheet, save it to a text field in an SQL Server database and then retrieve that document, etc. and open it in Word or Excel.
Well, I'm trying to reproduce this in C#, and the function that was provided in the VFPToolkitNET only seems to work with text strings, but when you attempt to open a Word Document it modifies the contents. See code below:
public static string FileToStr(string cFileName)
{
//Create a StreamReader and open the file
StreamReader oReader = System.IO.File.OpenText(cFileName);
//Read all the contents of the file in a string
string lcString = oReader.ReadToEnd();
//Close the StreamReader and return the string
oReader.Close();
return lcString;
}
How can I reproduce this functionality in C# without modifying the contents of the file upon reading it? Thanks!!
bob
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only