"so this is a bit of a strange question: i would like to serialize (to binary) an
embedded resource of my project."
try and specify wat it is...
"I normally perform serialization via a binary formatter using a file stream.
I have problems using the resource as a parameter to the filestream constructor as it wants a string/handle while my resource is a byte[] casting to a string/handle also doesn't seam to solve the problem."
"I tried creating a serializable class which holds a only a string. But again i am not able to read the resource using a stream so that i may fill and then
serialize that class."
i normally use a class to do serializing..here is a sample code with byte array..
-
-
using System.IO;
-
using System.Xml.Serialization;
-
-
using System.Runtime.Serialization.Formatters.Binary;
-
using System.Runtime.Serialization;
-
-
public Program Dese(Program now)
-
{
-
XmlSerializer serial = new XmlSerializer(typeof(Program));
-
-
BinaryFormatter formatter = new BinaryFormatter();
-
-
//using (FileStream str = new FileStream(@"C:\byte.xml", FileMode.Open))
-
//{
-
// now = (Program)serial.Deserialize(str);
-
// //str.Dispose();
-
//}
-
-
using(FileStream str=new FileStream(@"C:\byte.123",FileMode.Open))
-
{
-
now=(Program)formatter.Deserialize(str);
-
}
-
-
return now;
-
}
-
public void serailize(Program now)
-
{
-
XmlSerializer serialize = new XmlSerializer(typeof(Program));
-
using (TextWriter writer = new StreamWriter(@"C:\byte.xml"))
-
{
-
serialize.Serialize(writer, now);
-
-
writer.Dispose();
-
}
-
-
BinaryFormatter formatter = new BinaryFormatter();
-
-
using (FileStream str = new FileStream(@"C:\byte.123", FileMode.OpenOrCreate))
-
{
-
formatter.Serialize(str,now);
-
}
-
-
-
}
-
public static byte[] StrToByteArray(string str)
-
{
-
-
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
-
return encoding.GetBytes(str);
-
}
-
-
-
///
-
-
[Serializable]
-
public class Program
-
{
-
public string ss = "prr";
-
-
public byte[] str;
-
static void Main(string[] args)
-
{
-
Program p = new Program();
-
p.str=Program.StrToByteArray("prr");
-
-
p.serailize(p);
-
-
Program c;
-
-
c=p.Dese(p);
-
Console.ReadLine();
-
}
-
/*
-
* byte [] dBytes = ...
-
string str;
-
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
-
str = enc.GetString(dBytes);
-
-
*/
-
-
i dint get any problem... though i have used byte array that much... i guess its pretty much same