none
Inserting html file inside content control range adds extra space at end in content control RRS feed

  • Question

  • Hi,

    I have a use case where i am getting the content control text change from a word document. I am sending the content control text as html(to keep the formatting). In content control exit event i do

    contentcontrol.Range.FormattedText.Copy(); or contentcontrol.Range.Copy()

    and then get html from clipboard 

    string HTMLCode = Clipboard.GetData(DataFormats.Html).ToString();

    The extra spaces are being inserted when i put this html in temp file and then insert it in the content control range:

    contentControl.Range.Text = "";
    contentControl.Range.FormattedText.InsertFile(tempFilename); or contentControl.Range.InsertFile(tempFilename);

    One other thing i noticed is that after repeating this insert html task multiple times the extra space is added for only first few repetitions and then the it does not adds more space in the content control.

    How can i stop this extra space added at the end of content control(the extra space is inside content control).

    Tuesday, November 19, 2019 5:44 AM

All replies

  • ON further analysis. i found that after inserting html file it adds \r at end of the range and deleting it using below works:
    Word.Range rng = doc.Range(contentControl.Range.End - 1, contentControl.Range.End);
    rng.Delete();
    Is it the only way to solve this? or i am doing something wrong in approach to accomplish the required result.
    • Edited by Sumit Pannu Tuesday, November 19, 2019 10:50 AM
    Tuesday, November 19, 2019 9:12 AM