Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Stream to String
Message
From
30/01/2006 21:46:33
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01091728
Message ID:
01091729
Views:
16
This message has been marked as the solution to the initial question of the thread.
>I want to convert an embedded resourse stream to a string. The following code does what I want it to:
>
>byte[] ba;
>using (System.IO.Stream s = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(sResouce))
>{
>  ba = new byte[s.Length];
>  s.Read(ba, 0, ba.Length);
>}
>
>string myString = System.Text.ASCIIEncoding.ASCII.GetString(ba);
>
>
>Is there a better way to do this? It just seems like a lot of work to first convert the Stream to a byte array and then convert it to a string.

This is what I use to do a VFP FileToStr() equivalent:
    ' FileToStr() VFP equivalent
    ' expC1 File name
    Public Shared Function FileToStr(ByVal tcFileName As String) As String
        Dim loFile As IO.StreamReader
        Dim lcString As String
        Try
            loFile = New IO.StreamReader(tcFileName, System.Text.Encoding.Default)
            lcString = loFile.ReadToEnd()
            loFile.Close()
        Catch loError As Exception
            Framework.App.ErrorSetup(loError)
            lcString = ""
        End Try
        Return lcString
    End Function
Once the stream reader object is created, I have to do ReadToEnd() to get the content.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform