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"]; } } |
// 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); |
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/_vti_bin/Copy.asmx. But before you do, you need to replace any illegal characters in the filename - in our case we replaced an illegal character with a hyphen.
internal static string ReplaceSpecialCharacters(string input) { Regex r = new Regex("(?:[^a-z0-9 ]|(?<=['\"])s)", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled); return r.Replace(input, "-"); } |
1 comment:
Great, thank you!
I'm using this method to prevent the saving of email attachment.
Post a Comment