Hi all.
Is it possible to take a binary file and out put it as text so that I
can store it in a text field of a database? And then later, take the
text and 're-stream' it as the original binary file. If so, any ideas
on where I could start?
I cannot store the file in any other format other than text so I can
only do a converstion to text and then back from it.
Thanks in advance. 7 1353
> Is it possible to take a binary file and out put it as text so that I can store it in a text field of a database? And then later, take the
You can use Convert class and its ToBase64String and FromBase64String
methods for such tasks.
--
Peter Macej
Helixoft - http://www.vbdocman.com
VBdocman - Automatic generator of technical documentation for VB, VB
..NET and ASP .NET code
Hugh Janus wrote: Is it possible to take a binary file and out put it as text so that I can store it in a text field of a database? And then later, take the text and 're-stream' it as the original binary file. If so, any ideas on where I could start?
I cannot store the file in any other format other than text so I can only do a converstion to text and then back from it.
I think you want to look at System.Convert.ToBase64
Andrew You can use Convert class and its ToBase64String and FromBase64String methods for such tasks.
Thanks for the quick reply. Do you (or anyone else) have any sample
code I can start with by any chance?
Hugh
Hello Hugh,
In general this is a TERRIBLE idea. You should try to avoid storing files
in a database if at all possible. Instead, think about storing just the
file path.
-Boo Hi all.
Is it possible to take a binary file and out put it as text so that I can store it in a text field of a database? And then later, take the text and 're-stream' it as the original binary file. If so, any ideas on where I could start?
I cannot store the file in any other format other than text so I can only do a converstion to text and then back from it.
Thanks in advance.
GhostInAK wrote: Hello Hugh,
In general this is a TERRIBLE idea. You should try to avoid storing files in a database if at all possible. Instead, think about storing just the file path.
-Boo
I totally agree, but it seems the only option I have and thats how my
boss wants it. Thankfully the files are all quite small so i don't
envisage too many probs DB wise. I just need a kick start with some
code!
Hugh
OK, I think I might be getting somewhere. I think I can convert the
file to text OK however, upon conversion back to a file it gives the
error "Longitud no válida para una cadena Base-64" which roughly
translates to "Length not valid for a Base-64 chain". Below is the
code I am using.
Any help would be greatly appreciated. My problem could be that the
decode is working fine but the encoding to Base64 is failing
perhaps??!!?!
Public Sub FileToText(ByVal FileName As String, ByVal
OutputFileName As String)
Dim TextWriter As New IO.StreamWriter(OutputFileName)
Dim NumBytesRead As Integer
Dim BytesToConvert(1000) As Byte
Dim Limit As Integer
Dim fs As New IO.FileStream(FileName, IO.FileMode.Open)
Do Until fs.Position = fs.Length
' Dim binaryData() As Byte =
Convert.ToBase64String(fs.Read)
NumBytesRead = fs.Read(BytesToConvert, 0,
BytesToConvert.Length)
TextWriter.Write(Convert.ToBase64String(BytesToCon vert)) ',
0, binaryData.Length)
Loop
fs.Close()
TextWriter.Close()
End Sub
Public Sub FileFromText(ByVal FileName As String, ByVal
OutputFileName As String)
Dim TextReader As New IO.StreamReader(FileName)
Dim strRead As String
Dim fs As New IO.FileStream(OutputFileName, IO.FileMode.Create)
Do
strRead = TextReader.Read.ToString
If Not strRead Is Nothing Then
Dim binaryData() As Byte =
Convert.FromBase64String(strRead)
fs.Write(binaryData, 0, binaryData.Length)
End If
Loop
fs.Close()
TextReader.Close()
End Sub
Hello Hugh,
Is there some reaosn you want to convert it to text? Most databi have a
method for storing binary data natively. I'm speaking off the top of my
head without lookin up the doco.. but SQL Server I know has a BINARY field
type and I believe it also has a VARBINARY (possibly).
-Boo GhostInAK wrote:
Hello Hugh,
In general this is a TERRIBLE idea. You should try to avoid storing files in a database if at all possible. Instead, think about storing just the file path.
-Boo I totally agree, but it seems the only option I have and thats how my boss wants it. Thankfully the files are all quite small so i don't envisage too many probs DB wise. I just need a kick start with some code!
Hugh This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Markus Ernst |
last post by:
Hi
I know this question is rather HTTP related than PHP, but I did not find an
HTTP group on my news server.
I deliver some files with the following PHP syntax:
header('Content-Description:...
|
by: googlegroups |
last post by:
I am playing with the XMLHTTPRequest method to perform client/server
transactions. I have it set up right now so that when readyState is 4,
it takes the XML and processes it. This works great until...
|
by: Eric Sabine |
last post by:
I have a web site where the user is able to download a file. I can't use an
anchor tag because I don't want the user to see where the filename is coming
from. Below is the code in which the user...
|
by: A.M-SG |
last post by:
Hi,
I have a ASP.NET aspx file that needs to pass large images from a network
storage to client browser. The requirement is that users cannot have access
to the network share. The aspx file...
|
by: |
last post by:
Hi all, is there a better way to stream binary data stored in a table in sql
2005 to a browser in .net 2.0? Or is the code same as in .net 1.1? We
noticed that in certain heavy load scenarios,...
|
by: DB |
last post by:
Hi All,
I’m trying to stream a PDF with .NET 2.0 in a c# web app. However, it does
not actually show the PDF (using adobe acrobat).
The Situation:
Click on a Button, Opens a new Window,...
|
by: Volte |
last post by:
Hey all. Been looking into this for a while now, got some mock ups and
whatnot. All works well (as far as the server "streaming" the data, via
a sleep and flush method right now just for...
|
by: Amjad |
last post by:
Hi i am writing a application where i want to browse video file and copy data
into stream and send that stream over network...I have develop P2P windows
application where i successfully transfer...
|
by: SPG |
last post by:
Hi,
Two questions for you all..
Firstly, is there a way of streaming video using PHP? At the moment I just
have a link to a video file and the whole thing downloads before playing
which is a...
|
by: Faisal Shafiq |
last post by:
I want to upload a file direct to the Silverlight Streaming Service from a
Web Client such as silverlight application.
As per our product requirement we want to upload a .WMV file directly from...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |