FileToString? StringToFile?
-
hai... everyone who know how to convert the File to String? Actually, my idea is doing this to transfer the file to another computer. So, i convert the file (.text file or .exe file) to string and then send to another pc. After this, the pc will received this string then convert the string to File... So, i build up the protocol already but i dont know how to convert the file to string and the convert back from string to file.... anyone can help me.....:wtf: thanks....
-
hai... everyone who know how to convert the File to String? Actually, my idea is doing this to transfer the file to another computer. So, i convert the file (.text file or .exe file) to string and then send to another pc. After this, the pc will received this string then convert the string to File... So, i build up the protocol already but i dont know how to convert the file to string and the convert back from string to file.... anyone can help me.....:wtf: thanks....
-
This might be a better way. Ignore the bits about saving it to the database. It converts a file to a Byte Array. I am currently saving pictures to a database in this way. It works great. http://support.microsoft.com/kb/316887[^] Shawn
Thanks for ur reply.... Actually i just know the code from BitMapToString, but i dont know how to use this to convert it from FileToString... So, any suggestion for this function.... Public Function BitmapToString(ByVal sImagePath As String) As String Try Dim data As String Dim ms As MemoryStream = New MemoryStream Dim bmp As Bitmap = New Bitmap(sImagePath) ' Save as PNG format (IMHO, much better! // ) bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png) data = Convert.ToBase64String(ms.ToArray()) Return data Catch ex As Exception Return String.Empty End Try End Function
-
Thanks for ur reply.... Actually i just know the code from BitMapToString, but i dont know how to use this to convert it from FileToString... So, any suggestion for this function.... Public Function BitmapToString(ByVal sImagePath As String) As String Try Dim data As String Dim ms As MemoryStream = New MemoryStream Dim bmp As Bitmap = New Bitmap(sImagePath) ' Save as PNG format (IMHO, much better! // ) bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png) data = Convert.ToBase64String(ms.ToArray()) Return data Catch ex As Exception Return String.Empty End Try End Function
You might want to try some of the code I have in a project I posted on this board about 2 weeks ago. It is using a MySql file but I think the streamreader code might work. http://www.codeproject.com/useritems/WavfilesInDatabases.asp Dim b() As Byte Try b = DBSelectCmd.ExecuteScalar() Dim K As Long K = UBound(b) Dim WriteFs As New FileStream(strOutFile, FileMode.Create, FileAccess.Write) WriteFs.Write(b, 0, K) WriteFs.Close() MessageBox.Show("Wav file has been retrieved and written to application folder") Catch oExcept As Exception MessageBox.Show(oExcept.Message) End Try If this doesn't work, I found some other similar code in MSDN that I think might work but I don't have it on this computer and I will have to wait until Monday to get it from my work computer. Let me know if this either does or doesn't work.
-
You might want to try some of the code I have in a project I posted on this board about 2 weeks ago. It is using a MySql file but I think the streamreader code might work. http://www.codeproject.com/useritems/WavfilesInDatabases.asp Dim b() As Byte Try b = DBSelectCmd.ExecuteScalar() Dim K As Long K = UBound(b) Dim WriteFs As New FileStream(strOutFile, FileMode.Create, FileAccess.Write) WriteFs.Write(b, 0, K) WriteFs.Close() MessageBox.Show("Wav file has been retrieved and written to application folder") Catch oExcept As Exception MessageBox.Show(oExcept.Message) End Try If this doesn't work, I found some other similar code in MSDN that I think might work but I don't have it on this computer and I will have to wait until Monday to get it from my work computer. Let me know if this either does or doesn't work.
:laugh:hai.. thanks for ur reply... Actually, i do many testing in filestream, but the results are just can convert the file(.txt file) to string. my friend told to me that this is can't to convert the (.exe file) to string. Is true? :confused:
-
:laugh:hai.. thanks for ur reply... Actually, i do many testing in filestream, but the results are just can convert the file(.txt file) to string. my friend told to me that this is can't to convert the (.exe file) to string. Is true? :confused:
See if this code might work. I don't know if you can "rebuild" data from a table back into a .exe, but I don't know of any reason why you shouldn't. If you FTP a file it is basically being "read" in binary, sent as a binary stream of data and then basically rebuild on the receiving end. Anyway check this out. Do While fdRead.Read() 'strTmp = fdRead.GetString(0) strProgramFile = fdRead.GetString(0) strOtherData = fdRead.GetString(1) strOtherData2 = fdRead.GetString(2) ' Create a file to hold the output. strFileOut = "progrname.exe" 'Me.TextBox2.Text & ".wav" fs = New FileStream(strFileOut, FileMode.OpenOrCreate, FileAccess.Write) bw = New BinaryWriter(fs) startIndex = 0 ' Read bytes into outbyte() and retain the number of bytes returned. retval = fdRead.GetBytes(1, startIndex, outbyte, 0, bufferSize) ' Continue reading and writing while there are bytes beyond the size of the buffer. Do While retval = bufferSize bw.Write(outbyte) bw.Flush() ' Reposition the start index to the end of the last buffer and fill the buffer. startIndex += bufferSize retval = fdRead.GetBytes(1, startIndex, outbyte, 0, bufferSize) Loop ' Write the remaining buffer. Try bw.Write(outbyte, 0, retval - 1) Catch End Try bw.Flush() ' Close the output file. bw.Close() fs.Close() Loop fdRead.Close() Let me know if this works or not.