This project is read-only.
Serialize a C-Sharp object into the cloud storage

Availability: SharpBox 1.0

The following example shows how to serialize a C-Sharp object in a file of an existing cloud storage. This example uses the implemented drop box storage provider, so it needs also a valid dropbox configuration. To get the sample up and running an own dropbox account is neccessary. Additionally a valid application key and secret is needed. If you don't have one, use our test-application.
            // build up the storage
            CloudStorage storage = new CloudStorage();

            // open the dropbox
            storage.Open(DropBox.DropBoxConfiguration.GetStandardConfiguration(), creds);

            // build our business object
            SampleClass sample = new SampleClass();
            sample.value1 = "Hello";
            sample.value2 = "World";
            sample.iv1 = 1;
            sample.iv2 = 2;
            
            // open the file stream
            ICloudFileSystemEntry file = storage.CreateFile(null, "ser.dat");
            Stream stream = file.GetContentStream(FileAccess.Write);

            // serialize with formatter
            BinaryFormatter bformatter = new BinaryFormatter();
            bformatter.Serialize(stream, sample);

            // close the stream
            stream.Close();

            // close the dropbox
            if (storage.IsOpened)
                storage.Close();

Last edited Aug 6, 2011 at 6:38 AM by dei79, version 3

Comments

No comments yet.