To achieve this we created a plugin on the PreCreate action of an annotation. Then in the execute method of the plugin you can instantiate the annotation entity
if (null != context && null != context.InputParameters)
{
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
// Obtain the target entity from the input parmameters.
Entity entity = (Entity)context.InputParameters["Target"];
}
}
Once you have the annotation then you can get the contents of the attachment as a byte array.
// Retrieve the base64Encoding document body
// and convert it to byte base64encoding
// see below for the DecodeFrom64 function
byte[] documentBody = DecodeFrom64(entity.Attributes["documentbody"].ToString());
// get the filename
System.IO.FileInfo annotationFileInfo = new System.IO.FileInfo(fileName);
To remove the attachment you need to use this code
entity.Attributes["documentbody"] = null;
entity.Attributes["filename"] = null;
entity.Attributes["filesize"] = null;
The helper method for decoding the attachment to a byte array
internal static byte[] DecodeFrom64(string encodedData)
{
byte[] encodedDataAsBytes = System.Convert.FromBase64String(encodedData);
return encodedDataAsBytes;
}
To upload the document to SharePoint you should use the CopyIntoItems method of the Copy web service located at http://sharepointurl
internal static string ReplaceSpecialCharacters(string input)
{
Regex r = new Regex("(?:[^a-z0-9 ]|(?<=['\"])s)", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled);
return r.Replace(input, "-");
}
I may have posted this code too late to help Maria, but I hope someone else finds it useful.