Almost every Entity in CRM has support for Notes and Attachments.
A Note could be almost any piece of text which does not fall under any of the CRM Activity types.(phone,fax,email etc.)
Attachment lets to attach any kind of documents (doc,xls,pdf,image files etc) to a particular record in CRM.


The Notes tab in CRM, allows you to create just a note, however if you need to create a note with an attachment, you will need to browse to Actions->Attach a Note on the menubar of the particular record.


All Notes go into the annotationbase table on the CRM DB.
Even attachments if any, associated with a note are stored in this table.
This architecture allows the attachements to the accessed even via the Outlook Client in Offline mode.


Imp: Only 1 file can be attached per Note.


Create Notes using the CRM SDK:
//Create a simple note
annotation note = new annotation();
note.notetext = "This is a note";
EntityNameReference entRef = new EntityNameReference();
entRef.Value = "account";
note.objecttypecode = entRef;
note.objectid = [GUID of the account record];
crmService.Create(note);


//Create note with an attachment
annotation note = new annotation();
note.notetext = "This is a note";
EntityNameReference entRef = new EntityNameReference();
entRef.Value = "account";
note.objecttypecode = entRef;
note.objectid = [GUID of the account record];
Guid noteID = crmService.Create(note);


UploadFromBase64DataAnnotationRequest uploadFile = new UploadFromBase64DataAnnotationRequest();
uploadFile.AnnotationId = noteID;
uploadFile.FileName = "Example.txt";
uploadFile.MimeType = "text/plain"; //Other possible values 'application/msword' for word doc
//Since this file would be stored in the CRM DB, the file must be converted to a base64 encoded string
uploadFile.Base64Data = GetBase64StringFromFile("Example.txt");
crmService.Execute(uploadFile);


private static string GetBase64StringFromFile(string filename) {
using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read)) {
using (BinaryReader reader = new BinaryReader(fs)) {
byte fileContent = reader.ReadBytes((int) fs.Length);
return Convert.ToBase64String(fileContent);
  }
 }
}


//Retrieve Attachment from CRM
On the CRM domain one can use the below url to download an attachment directly from the CRM Server
http:///[organization name]/Activities/Attachment/download.aspx?AttachmentType=5&AttachmentId=[Annotation ID]


The above url will prompt the user to either Open or Save the the particular attachment.


//The below SDK approach can also be used to download an attachment
Private byte GetAnnotationAttachment(Guid annotationId){
Guid attachid = annotationId;
//Pass the Annotation attachment OTC and the Annotation ID
http:///[organization name]/Activities/Attachment/download.aspx?AttachmentType=5&AttachmentId=[Annotation ID]
System.Net.WebClient myWebClient = new System.Net.WebClient();
myWebClient.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
return myWebClient.DownloadData(url);
}


byte exampleByteArray1 = GetAnnotationAttachment(new Guid("D7D5E13B-E3B4-DE11-A647-00012E0B81A2"));
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Transfer-Encoding", "binary");
Response.AppendHeader("content-disposition", "attachment; filename=" + "Sample.xls");
Response.BinaryWrite(exampleByteArray1);