Skip to main content

Posts

Showing posts from 2008

VSTO - Use RichTextBox with Range

In VSTO project, we can use WinForm dialog with RichTextBox to allow user to input rich formatted text. The Rtf property of RichTextBox returns the string representing the content in Rtf format. However, there is no direct way to insert the Rtf content into Word Range object. The Text property of Range object only accept plain text and there is no Rtf property in Range object. After the long search and experiment, I found out that the only way to communicate between RichTextBox and Range object is via Clipboard. From RichTextBox to Range: Private Sub InsertRtf(ByRef strRtfMessage As String, ByRef oRange As Word.Range) With oRange.FormattedText .Style = "Body Single" Clipboard.Clear() Clipboard.SetData(DataFormats.Rtf, strRtfMessage) .Paste() End With End Sub From Range to RichTextBox: Private Function TransformRangeToRtf(ByRef oRange As Word.Range, ByRef rtfMsg As RichTextBox) As String oRange.Copy() rtbMsg

VSTO Spelling Check - Use different dictionary

When we are using Spelling check function of Word, sometime we may need to use a different dictionary than the default one. The default dictionary is determined by default language. In Word.Application object, there is a property called Language, but it is read only and can not be changed. After some search on Google, I finally find that Word.Range object has a property called LanguageID, which you can set to change the dictionary used in spelling check. Following code snippet shows how to use different dictionary: Private Function CheckRangeSpelling(ByRef oRange As Word.Range) As Boolean ' Grab the text before spell checking Dim strText As String = oRange.Text ' Check the spelling using French Canadian dictionary oRange.NoProofing = False oRange.LanguageID = Word.WdLanguageID.wdFrenchCanadian oRange.CheckSpelling() ' Check if user has changed anything during the spell checking If strText <> oRange.Text Then

ASP.NET AJAX Page Method

Page method is a static special method in ASP.NET page code behind. Using page method is an easy way to reduce post backs in your web page. In order to use Page method, you need to follow these steps: 1. In your ASP.NET web page, add the following line inside form tag <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"> 2. Inside your ASP.NET web page code behind, define a public static method as page method: [ WebMethod ()] public static string [] GetList( string [] arrList) { string [] arrNewList = new string [arrList.Length + 1]; for ( int i = 0; i < arrNewList.Length; i++) { arrNewList[i] = "Item " + i; } return arrNewList; } 3. In your aspx file, add the javascript event handler for the control's client onclick or onchange events. <script type= "text/javascript" language= "javascript" > var ddlControl; function InvokePa

Create watermark in VSTO Word document

Use the following code to create a watermark inside Word document. Public Shared Function CreateWaterMark(ByRef oDoc As ThisDocument, ByVal WatermarkText As String) Dim wmShape As Word.Shape 'Create the watermark shape wmShape = oDoc.Shapes.AddTextEffect( _ Microsoft.Office.Core.MsoPresetTextEffect.msoTextEffect1, _ WatermarkText, "Times New Roman", 96, False, True, 0, 0) 'Set all of the attributes of the watermark With wmShape .Select() .Name = "PowerPlusWaterMarkObject1" .TextEffect.NormalizedHeight = False ' Create a hollow text .Line.Visible = True .Line.ForeColor.RGB = Word.WdColor.wdColorGray25 .Fill.Visible = False .LockAspectRatio = True .Rotation = 315 ' Positioning the watermark .RelativeVerticalPosition = Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin .Relat

SharePoint Form Controls

When you are writting aspx page for SharePoint 2003/2007, you can use the controls provided by SharePoint to maintain the same form style like this: In order to use these controls, you need to add these lines in the top of your aspx page: <%@ Register TagPrefix="wssuc" TagName="InputFormSection" src="~/_controltemplates/InputFormSection.ascx" %> <%@ Register TagPrefix="wssuc" TagName="InputFormControl" src="~/_controltemplates/InputFormControl.ascx" %> <%@ Register TagPrefix="wssuc" TagName="ButtonSection" src="~/_controltemplates/ButtonSection.ascx" %> Also, you need to put all these controls inside a HTML table tag: Here is the code snippet that generates the above form: <table border="0" width="100%" cellspacing="0" cellpadding="0" id="diidProjectPageOverview"> <wssuc:InputFormSection Title="Locale"

Deploy VSTO solution into SharePoint document library

Visual Studio Tools for Office (VSTO) is a powerful tool to develop office based application. By deploying the VSTO solution into SharePoint document library, it will greatly reduce the maintenance effort (No need to push all the files into client machine). Deployment architecture There are 3 machines involved in deployment: 1. SharePoint server: The VSTO document (dot, doc, xlt or xls, etc) is uploaded to SharePoint server (either in document library or as document template). 2. File server: This server contains all the supporting files of VSTO document (.dll and configuration files, etc). 3. Client manchine: This is the client. The only thing need to be done is create security policy to specify the location of VSTO document and assembly. Steps to deploy VSTO solution to SharePoint document library. 1. Create a VSTO project. Let's assume the project name is Proposal . It contains a Word template file Proposal.dot file. The project compiles into an assembly called Proposal.dll. Pub