Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Reading and writing files in c#
Message
De
31/03/2009 21:39:25
 
 
À
31/03/2009 13:53:03
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01392440
Message ID:
01392515
Vues:
65
Perfect! Thanks!!

bob


>>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform