Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Reading and writing files in c#
Message
From
31/03/2009 13:53:03
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
31/03/2009 13:21:00
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01392440
Message ID:
01392452
Views:
67
>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

VFPToolkitNet though is good for starters, some functions implementations are not right or doesn't match with the behaviours of VFP counterpart.
string fileName = @"c:\my folder\anyTypeFile.ext";

byte[] fileContent = File.ReadAllBytes(fileName);
PS: For large files you may prefer to do buffered reads.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform