Byte Conversion
-
Hi all, im having a problem with retrieving a binary file from the database and reading it in my code, so far i have this: byte AttachmentByte = new byte(); AttachmentByte = StringToByteArray(inputString); and a function to convert it: public static byte[] StringToByteArray(string inputString) { System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); return encoding.GetBytes(inputString); } but when i run it i get the error: Cannot implicitly convert type 'byte[]' to 'byte' can someone please tell me what im doing wrong. thanks in advance!
living life on the flip side
-
Hi all, im having a problem with retrieving a binary file from the database and reading it in my code, so far i have this: byte AttachmentByte = new byte(); AttachmentByte = StringToByteArray(inputString); and a function to convert it: public static byte[] StringToByteArray(string inputString) { System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); return encoding.GetBytes(inputString); } but when i run it i get the error: Cannot implicitly convert type 'byte[]' to 'byte' can someone please tell me what im doing wrong. thanks in advance!
living life on the flip side
StringToByteArray returns byte[] while AttachmentByte is defined as byte.
Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion
-
Hi all, im having a problem with retrieving a binary file from the database and reading it in my code, so far i have this: byte AttachmentByte = new byte(); AttachmentByte = StringToByteArray(inputString); and a function to convert it: public static byte[] StringToByteArray(string inputString) { System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); return encoding.GetBytes(inputString); } but when i run it i get the error: Cannot implicitly convert type 'byte[]' to 'byte' can someone please tell me what im doing wrong. thanks in advance!
living life on the flip side
Agweet wrote:
byte AttachmentByte = new byte(); AttachmentByte = StringToByteArray(inputString);
byte[] AttachmentByte;
AttachmentByte = StringToByteArray(inputString);Navaneeth How to use google | Ask smart questions
-
Agweet wrote:
byte AttachmentByte = new byte(); AttachmentByte = StringToByteArray(inputString);
byte[] AttachmentByte;
AttachmentByte = StringToByteArray(inputString);Navaneeth How to use google | Ask smart questions
Hi guys, thanks for the quick replies, the problem is that i tried using:
byte[] AttachmentByte;
then it gives the error on the filestream:
using (System.IO.FileStream fs = System.IO.File.Create(newPath))
{
fs.WriteByte(AttachmentByte);
}i get the errors: The best overloaded method match for 'System.IO.Stream.WriteByte(byte)' has some invalid arguments Argument '1': cannot convert from 'byte[]' to 'byte' is there something else im missing?
living life on the flip side
-
Hi guys, thanks for the quick replies, the problem is that i tried using:
byte[] AttachmentByte;
then it gives the error on the filestream:
using (System.IO.FileStream fs = System.IO.File.Create(newPath))
{
fs.WriteByte(AttachmentByte);
}i get the errors: The best overloaded method match for 'System.IO.Stream.WriteByte(byte)' has some invalid arguments Argument '1': cannot convert from 'byte[]' to 'byte' is there something else im missing?
living life on the flip side
Agweet wrote:
is there something else im missing?
Yes. A good C# book. Seriously, the error message you got is self explanatory. It has some invalid arguments. Look at the documentation for that method and see what arguments it expects. BTW, this some different code you are showing than the one given in the original post.
Navaneeth How to use google | Ask smart questions
-
Hi guys, thanks for the quick replies, the problem is that i tried using:
byte[] AttachmentByte;
then it gives the error on the filestream:
using (System.IO.FileStream fs = System.IO.File.Create(newPath))
{
fs.WriteByte(AttachmentByte);
}i get the errors: The best overloaded method match for 'System.IO.Stream.WriteByte(byte)' has some invalid arguments Argument '1': cannot convert from 'byte[]' to 'byte' is there something else im missing?
living life on the flip side
WriteByte writes just a single byte to the stream but you need to write byte[] so use the overload that writes byte[] to the stream. That's it :)
Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion
-
Agweet wrote:
is there something else im missing?
Yes. A good C# book. Seriously, the error message you got is self explanatory. It has some invalid arguments. Look at the documentation for that method and see what arguments it expects. BTW, this some different code you are showing than the one given in the original post.
Navaneeth How to use google | Ask smart questions
thanks once again for the reply, i know that i posted other code...im trying to retrieve a binary file stored in the database and write it to my local machine, with use of creating a folder and using a filestream. thanks for all the advise :)
living life on the flip side
-
WriteByte writes just a single byte to the stream but you need to write byte[] so use the overload that writes byte[] to the stream. That's it :)
Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion
-
Hi Giorgi, sorry but i have never used filestreams or binary files before, how would i go about using the overload that writes byte[]?
living life on the flip side
As suggested by Navaneeth you need a good C# book. As for FileStream, you can have a look at its method at this msdn link: FileStream Methods[^]
Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion
-
As suggested by Navaneeth you need a good C# book. As for FileStream, you can have a look at its method at this msdn link: FileStream Methods[^]
Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion