Blog Stats
  • Posts - 14
  • Articles - 1
  • Comments - 25
  • Trackbacks - 0

 

Friday, June 13, 2014

C# Replace Macros in Word Document .docx


One of my clients had users downloading a word document to edit and print out. Some of these fields in the Word Document can be pre-populated with data.

There is a dll called DocX available here: http://docx.codeplex.com/

Keep in mind, this only works with .docx, not .doc file formates

Sample code:

private void GetDocument()

        {

            //Get parameters

            string FirstName = "Benjamin";

            string LastName = "Adler";

            string Username = "Badler";

 

            //Get template

            string TemplateFileName = @"C:\temp\test.docx";

            DocX template = DocX.Load(TemplateFileName);

           

            //Replace macros with parameters

            template.ReplaceText("%FirstName%", FirstName, false, System.Text.RegularExpressions.RegexOptions.Singleline, null, null, MatchFormattingOptions.ExactMatch);

            template.ReplaceText("%LastName%", LastName, false, System.Text.RegularExpressions.RegexOptions.Singleline, null, null, MatchFormattingOptions.ExactMatch);

           

            //Save with new file name

            string newFile = string.Format(@"C:\temp\test_{0}.docx", Username);

            template.SaveAs(newFile);

        }


Monday, August 20, 2012

MSChart disappearing on postback


MSChart disappears on postback. The easiest fix is to simply enable viewstate, which is turned off by default:

<asp:Chart runat="server" ID="chartMyChart" EnableViewState="true" >


Friday, August 17, 2012

Getting MSChart to work on buildserver webserver with framework 3.5


MSCharting is a tool that helps you create all sorts of graphs in .NET. If you are using framework 3.5, you’ll need to install this: https://www.microsoft.com/en-us/download/details.aspx?id=14422

 And this addon to make it display in toolbox and for intellisense: https://www.microsoft.com/en-us/download/details.aspx?id=23903

If you are using framework 3.5, you’ll need to either install the charting controls on each server that you are working on, or you can include the dlls in your project instead and reference these dlls as if they were coming from a 3rd party.

When you install the Charting Controls, they are located here C:\Program Files\Microsoft Chart Controls. Now you can reference them in your project if needed.

 

Thursday, July 12, 2012

Report Builder 2.0 - Requested value 'Integrated' was not found.


 

I was trying to open a .rdl file but could not due to an error:

Requested value 'Integrated' was not found.

I could open the .rdl in Report Builder 3.0, but I couldn’t upload it to the reporting server because it was the wrong schema. I also couldn’t open the .rdl that was saved in 3.0 in 2.0 for the same reason.

I didn’t want to go through the time of installing Business Intelligence Studio. I discovered I didn’t have to:

1.       Open .rdl in notepad to edit the XML

2.       Replace <rd:SecurityType>Integrated</rd:SecurityType>

with <rd:SecurityType>Windows</rd:SecurityType>

3.       Save and open the .rdl in Report Builder 2.0!

 

 

 

 

 

Friday, October 21, 2011

Ajaxtoolkit HTMLEditor color picker position not visible off screen


I was working with the built in ajaxtooljit HTMLEditor and for some odd reason, the color picker was showing off the screen. I noticed that the "TextEditorDivContainer" class of the control had position absolute.

To solve this problem, I had to wrap the editor in a div with a class named "EditorWrapper" and change the position of the "TextEditorDivContainer" class to static.

 

.EditorWrapper .TextEditorDivContainer {     position: static !important; }

 

Thursday, September 22, 2011

jwplayer file not found or access denied checklist


A common problem when using jwplayer is "file not found or access denied".

Here are a few things to check for:

1.       If you are using mp4, be sure to have the MIME type added in IIS. The MIME type for .mp4 is video/mp4. The video will work in a test html page without a MIME type, but you’ll need to add one when working with ASP.net

2.       Be sure the file location is correct and that the file exist and is named correctly. You may want to try using an absolute web path name inside the javascript for testing purposes.

3.       Check your relative file path. Some versions of the player (v5.3), a relative path must be relative to the SWF file, other versions, the relative path must be relative to the html which the SWF is embedded (v5.4) . See here http://www.longtailvideo.com/support/forums/jw-player/video-encoding/12978/mp4h274-video-not-found-or-access-denied

4.       Be sure you are using forward slashes instead of backslashes in the file name

5.       View the source of the javascript to confirm it's correct.

Wednesday, September 14, 2011

The tail of the log for the database "%ls" has not been backed up.


I was working locally and trying to restore a database backup from the server for development purposes. I was receiving this error when I tried to restore and overwrite an existing database:

The tail of the log for the database "%ls" has not been backed up. Use BACKUP LOG WITH NORECOVERY to back up the log if it contains work that you do not want to lose. Use the WITH REPLACE or WITH STOPAT clause of the RESTORE statement to just overwrite the contents of the log.

An easy fix is to click on the Options page and click 'Overwrite the existing database (WITH REPLACE).

More info here: http://msdn.microsoft.com/en-us/library/bb283410.aspx

 

 

Tuesday, July 12, 2011

jQuery UI Progressbar 1.8.7 transparent / height fix


I noticed while using the jQuery UI Progressbar 1.8.7 that there was some extra space at the bottom of the progress bar. Turns out there was a bug in the jQueryUI/aristo/jquery-ui.css file, and adding a white background fixed the problem.

.ui-progressbar { height: 12px; text-align: left; background: url(images/progress_bar.gif) 0 -14px repeat-x; }

 should be
 

.ui-progressbar { height: 12px; text-align: left; background: url(images/progress_bar.gif) 0 -14px repeat-x #ffffff; }

 

Monday, June 6, 2011

SQL Specific Order By


order by

(case

      when id = 5 then 1

      when id = 2 then 2

      when id = 3 then 3

      when id = 1 then 4

      when id = 4 then 5

end) asc

Friday, May 27, 2011

jquery fullcalendar disable prev previous button


I'm using the fullcalendar from: arshaw.com/fullcalendar/ version 1.5.1

I'm only using the month view and wanted to disable the previous buttons so that the user could not view months in the past.

Inside the renderView(inc) function in the FullCalendar.js file, I added this on line 408:


  //This disables the previous buttons so that the user cannot view previous months/years 

                if (today.getMonth() >= parseDate(currentView.start).getMonth() && today.getFullYear() >= parseDate(currentView.start).getFullYear())

                {

                    header.disableButton('prev');

                    header.disableButton('prevYear');

                }

                else if (parseDate(currentView.start).getFullYear() <= today.getFullYear())

                {

                    header.enableButton('prev');

                    header.disableButton('prevYear');

                }

                else if(parseDate(currentView.start).getFullYear() > today.getFullYear() &&  parseDate(currentView.start).getMonth() >= today.getMonth())

                {

                    header.enableButton('prev');

                    header.enableButton('prevYear');

                }

 

 

Copyright © BenAdler