Skip to content

Instantly share code, notes, and snippets.

@tgjones
Created March 10, 2011 16:42

Revisions

  1. Tim Jones created this gist Mar 10, 2011.
    30 changes: 30 additions & 0 deletions gistfile1.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    public class Asset : Document<Asset>
    {
    public string Title { get; set; }
    public Attachment File { get; set; }
    }

    Attachment file = Attachment.Create("Files/Koala.jpg", "image/jpg");

    Asset asset = new Asset
    {
    Title = "The Title",
    File = file
    };
    asset.Save();

    /*
    {
    "_id": {
    "$oid": "4d78ff2002df531d487fdbcc"
    },
    "_t": "Asset",
    "Title": "The Title",
    "File": {
    "$oid": "4d78ff1f02df531d487fdbc6"
    }
    }
    */

    Asset theAsset = Asset.FindByID(asset.ID);
    string fileName = theAsset.File.FileName;