473,382 Members | 1,252 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,382 software developers and data experts.

writing object to file system

I know it must be a very simple thing to do but I'm just brain dead today...
sorry...

how can I save an object to the filesystem??

object obj = GetMyObject();

// insert code to save to file system...

Please HELP...

thanks.

Alex
Nov 16 '05 #1
2 9986
Alex,

If the object is marked with the Serializable attribute, then you can
create a BinaryFormatter and then serialize it to a filestream, like so:

// Create a file stream.
using (FileStream fileStream = new FileStream(@"c:\temp\obj.bin",
FileMode.CreateNew, FileAccess.Write, FileShare.None))
{
// Create a formatter.
IFormatter formatter = new BinaryFormatter();

// Serialize.
formatter.Serialize(fileStream, obj);
}

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Alex Wagner" <gb*****@hot-nospam-mail.com> wrote in message
news:OS**************@TK2MSFTNGP09.phx.gbl...
I know it must be a very simple thing to do but I'm just brain dead
today...
sorry...

how can I save an object to the filesystem??

object obj = GetMyObject();

// insert code to save to file system...

Please HELP...

thanks.

Alex

Nov 16 '05 #2
Check out the XmlSerializer or the BinaryFormatter (depending on your
needs).

"Alex Wagner" <gb*****@hot-nospam-mail.com> wrote in message
news:OS**************@TK2MSFTNGP09.phx.gbl...
I know it must be a very simple thing to do but I'm just brain dead today... sorry...

how can I save an object to the filesystem??

object obj = GetMyObject();

// insert code to save to file system...

Please HELP...

thanks.

Alex

Nov 16 '05 #3

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

Similar topics

2
by: melanieab | last post by:
Hi, I'm trying to store all of my data into one file (there're about 140 things to keep track of). I have no problem reading a specific string from the array file, but I wasn't sure how to...
2
by: John Salerno | last post by:
I wrote this code just to experiment with writing to and reading from a file. It seems to work fine when writing, but when reading the file, it only prints the filepath to the screen, not the file...
5
by: Iceman | last post by:
I am logging things to a file but when I kill the app and restart it, all the other logging is gone. How can I prevent this form happening?
2
by: Richard Thornley | last post by:
Hello, I am working on a VB.Net application and I am getting an error ONLY on the main computer that uses the application. The main computer is on the other coast so of course it would be the...
16
by: iwdu15 | last post by:
how can i open a file i saved and place the info into different text boxes?
12
by: Martyn Fewtrell | last post by:
Hi there I'm trying to find the correct way to write exceptions to the Application log using Vb.Net. I've done a fair bit of Googleing and although this gets plenty of mentions and that this...
2
by: ThatsIT.net.au | last post by:
I have this code that writes a pie chart in a asp.net page, but I want to use it in a server control. When I try I get a error on the last line "Response.OutputStream" Obviously there is no...
0
ashitpro
by: ashitpro | last post by:
Writing System Call Wrappers in User Space. Recently I saw a post in Linux/Unix section to know the user who deleted the file in linux. Currently there is nothing in linux which could achieve...
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...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.