Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created March 1, 2017 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/6400f3d6f20aba64d34c6b6141ae09d1 to your computer and use it in GitHub Desktop.
Save bjoerntx/6400f3d6f20aba64d34c6b6141ae09d1 to your computer and use it in GitHub Desktop.
[HttpPost]
public string InsertSubTextPart(string Name, string BinaryDocument, bool Protected)
{
byte[] data = null;
// create a temporary ServerTextControl to create the
// SubTextPart
using (ServerTextControl tx = new ServerTextControl())
{
tx.Create();
// load the Selection from the Web.TextControl
tx.Load(Convert.FromBase64String(BinaryDocument),
BinaryStreamType.InternalUnicodeFormat);
tx.SelectAll();
int iTextLength = tx.Selection.Length;
// create a new SubTextPart over the complete text
SubTextPart part = new SubTextPart("txmb_" + Name,
Convert.ToInt32(Protected), 1, iTextLength);
tx.SubTextParts.Add(part);
// save the complete document
tx.SelectAll();
tx.Selection.Save(out data, BinaryStreamType.InternalUnicodeFormat);
}
// return the Selection as a Base64 encoded string
return Convert.ToBase64String(data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment