473,327 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Send a string directly to a file

Hi, any way to send a string directly to a file on the hard drive?

Thanks!

Greg
Nov 21 '05 #1
3 1186
I have been using these for a while... May fit the bill:

Public Function FILE_ReadIntoString(ByVal FileNameAndPath As String) As
String

Try

Dim myfile As System.IO.File

Dim Line As String

'Dim myStream As System.IO.FileStream

If myfile.Exists(FileNameAndPath) = True Then

' Create a file to write to.

Dim myStream As System.IO.StreamReader = myfile.OpenText(FileNameAndPath)

FILE_ReadIntoString = myStream.ReadToEnd

myStream.Close()

Else

App_Print("ERROR: FILE_ReadIntoString: Could not find file: " &
FileNameAndPath)

End If

'The problem is not so much loading files into strings as what happens next

'in the code. Adding this line should help .Net make room.

GC.Collect()

Catch ex As Exception

FILE_ReadIntoString = ""

App_Print("Error - FILE_ReadIntoString: " & ex.ToString)

End Try

End Function

Public Function FILE_WriteFile(ByVal OutputString As String, ByVal
OutputFileName As String) As Boolean

Try

Dim myFile As System.IO.File

Dim myFileStream As System.IO.FileStream

Dim myByteArray As Byte()

Dim MyEncoder As New System.Text.ASCIIEncoding

myFileStream = myFile.Create(OutputFileName)

myByteArray = MyEncoder.GetBytes(OutputString)

myFileStream.Write(myByteArray, 0, myByteArray.Length)

myFileStream.Close()

FILE_WriteFile = True

Catch ex As Exception

FILE_WriteFile = False

App_Print("Error - FILE_WriteFile: " & ex.ToString)

End Try

End Function

"Greg Chu" <gr******@wendys.com> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
Hi, any way to send a string directly to a file on the hard drive?

Thanks!

Greg

Nov 21 '05 #2
"Greg Chu" <gr******@wendys.com> schrieb:
Hi, any way to send a string directly to a file on the hard drive?


Take a look at the 'System.IO.StreamWriter' class...

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #3
Greg,

The streamwriter/streamreader pages on MSDN are full of samples.

Here the streamwriter.

http://msdn.microsoft.com/library/de...ClassTopic.asp

I hope this helps,

Cor
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: James Hong | last post by:
Help please, I try to sending an email from my html page using the java applet. but it give error on most of the PC only very few work, what is the error i make the java applet show as below ...
3
by: Roberto | last post by:
I have the following problem: I have the following form client side: <FORM.......> <FORM action="./WZUpload.asp" method="Post" enctype="multipart/form-data" WIDTH=100%> <INPUT Type="file"...
2
by: Fatih BOY | last post by:
Hi, I want to send a report from a windows application to a web page like 'report.asp' Currently i can send it via post method with a context like local=En&Username=fatih&UserId=45&Firm=none...
2
by: a | last post by:
how to send an xml dataset to a Stored Procedure in mssql I have an xml file that I read into a dataset. and I'm trying to use a stored procedure (see SPROC #1 below) that inserts this xml...
10
by: Aj Blosser | last post by:
Hey guys, I have a question for you, I have a setup where I'm sending files through the POST to a php web page, I read the file contents, put that file contents as text into the POST string, and...
13
by: Susan Beebe | last post by:
I have downloaded the code described in Microsoft article Q154078. I am trying to send raw ZPL (zebra barcode printer) code from Microsoft access. It works just fine if I hard code the actual...
6
by: ShieldsJared | last post by:
Hello all, I've been working on an application for a while now and have now come to a standstill. I have an application that I intend to have stored on a file server (developed in C#), which...
1
by: zivon | last post by:
now for the bigger problam :) I know you pepole hate using OE for sending emails, but its user friendly and its needed in this case... I found on this forum, a code that sends email using OE...
3
digicrowd
by: digicrowd | last post by:
http://bytes.com/images/howtos/applemail_sig_icon.jpg You can make your emails fancy in Mail.app by using Rich Text formatting or even included Stationery. But, a simple way to send your own HTML...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.