Yes! Now I got a good solution after doing some more research. As a topic that I posted "How to read a byte array in FileStream". We cannot read the byte array in FileStream, it is simply used to read the driver file for the byte array. So I changed my code a bit and now I have a file to read it with FileStream. How did i make the file?
In this context, I have an object. An object is all you need!
I use the collection as a samble object.
Collection<object> list = new Collection<object>(); //Now I will write this list to a file. fileName is what you want and be sure that folder Files is exist on server or at the root folder of your project WriteFile(list, Server.MapPath("~/Files/" + fileName)); //The method to write object to file is here public static void WriteFile<T>(T obj, string path) { FileStream serializeStream = new FileStream(path, FileMode.Create); BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(serializeStream, obj); serializeStream.Flush(); serializeStream.Close(); }
After I wrote my object to a file, I need a method to read it back to the object. Therefore, I am writing this method:
public static Collection<object> ReatFile(string fileName){
Having taken a few steps above, I can now write any type object to a file, and then read it back to the original object. Thanks so much for any help I received there.
source share