Posts

Donate

Generate Page Numbers Of Word Document Using OpenXML

Hello, I've been working on OpenXML framework specifically for generating reports on a Word Document. One of the task of the project is to add page numbers to a document with the format of "Page 1 of 72". After doing some researches on stackoverflow and google, I found a few links with functions on how to add page numbers but not in the format as specified for my requirement. In case you need to add page numbers to a word document specifically in the footer area, see function below. private Footer GeneratePageNumbers ( string FooterText) { var element = new Footer ( new Paragraph ( new ParagraphProperties ( new ParagraphStyleId () { Val = "Footer" }, new Justification () { Val = JustificationValues.Center }), new Run ( new Text () { Text = FooterText, Space = SpaceProcessingModeValues.Preserve }), new Run ( new SimpleField () { Instruction = "Page" }), new Run ( new Text () { Te...

Return Multiple Values From C# Asynchronous Function

Good evening fellow developers! I have a simple application that queries the database and returns list of employees and list of their dependents. Since I've just started learning async programming, I wonder if I could return multiple values for an asynchronous function or method. The initial solution that I have is to create a view model class that has two properties specifically list of employees and list of dependents. And this view model class will be the return type of the function. After reading through the docs, it's possible to return multiple values using System.ValueTuple namespace. If the target framework of the project is 4.6.2 and below, you need to add the System.ValueTuple NuGet package using NuGet Console Manager or add the package using Manage NuGet Package tool. For now, lets install the package using console manager. Install-Package "System.ValueTuple" Next is to modify the existing method to return multiple values using System.ValueTuple. pr...

SQL Server : Login Success But “The database [dbName] is not accessible.” After Domain Migration Using New Domain User

Image
Recently, our systems administrator has just finished migrating our workstations from an old domain to a new domain. But this caused an issue wherein most of the databases are not accessible. I've done several workarounds from stackoverflow and non of them worked. The solution that worked is to add my new domain user to the databases using SQL Server Authentication (sa) and set my new domain user as dbOwner.

How Get Total Number Of Rows From SQLDataReader Object Using C#

Good Evening Gents! In the office, we were using SQLDataReader class to read from SQL Server database in a straight-forward manner. The SQLDataReader has several properties that are commonly used such as HasRows and FieldCount. However in one of my task, I want to retrieve the total number of rows returned from the SQLDataReader object and there's no such property that support this. Doing some search led me to this link How to get number of rows using SqlDataReader in C# . The one that worked for me was the answer using select @@ROWCOUNT query. I modified his answer by writing my own method that will accept a List of SQLParameters given that the original query requires parameters. private static void GetTotalRowCount( string query, string connectionString, ref int totalRows, List<SqlParameter> sqlParameters) { try { using ( var sqlCon = new SqlConnection(connectionString)) { sqlCon.Open(); var cmd = sqlCon.CreateCommand(); cmd.CommandText = q...

This Site Can’t Provide a Secure Connection Localhost Sent An Invalid Response In ASP Classic Website

Good afternoon fellow programmers! In the event that you added an ASP Classic site to Visual Studio and when you debug or run the site, it produced an error such as "This site can’t provide a secure connection localhost sent an invalid response. Try running Windows Network Diagnostics. ERR_SSL_PROTOCOL_ERROR". The fix to this error is to comment or remove the rewrite rule in web.config. A sample rewrite node looks like this in web.config. <?xml version="1.0"?> <configuration> <system.webServer> <!--<rewrite> <rules> <rule name="Redirect to HTTPs" stopProcessing="true"> <match url="(.*)"/> <conditions> <add input="{HTTPS}" pattern="^OFF$"/> </conditions> <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther"/> ...

Response Buffer Limit Exceeded. Execution of the ASP Page Caused The Response Buffer To Exceed Its Configured Limit

Good evening fellow developers! I've been given a project to rewrite an existing ASP Classic Website written in VBScript to ASP.NET MVC. For now, I'm on research stage and familiarization of the existing modules and page functionalities. The site is fully functional but some of the pages rendered an error called "Response Buffer Limit Exceeded". After doing some google search, the solution that worked for me is to set the Response Buffer of the page to false right after Language declaration. <%@ LANGUAGE = "VBSCRIPT" %> <% Response.Buffer = False %> Reference: Response Buffer Limit Exceeded Cheers! :)

Visual Studio And WPF Menu Items Are Left Aligned Instead Of Right Aligned

Image
Hello, We noticed lately that our WPF Projects menu items and Visual Studio menu items are left aligned rather than right aligned. However, not all desktop were affected by this issue. Further research led me here Windows 10 Drop-Down Menus Are Aligned To The Left in which you have to execute a shell command shell:::{80F3F1D5-FECA-45F3-BC32-752C152E456E} via Windows + R command. This will open the Tablet PC Settings with Right-Handed radio button checked. Changing it to Left-Handed then Apply will change the menu items alignment to the right. Visual Studio Menu Items Are Now Right Aligned

Parse And Replace Element Attribute Value Of Script Template Using jQuery

Good afternoon fellow programmers! I recently have a task to load a Script template that contains HTML markup to a page dynamically. But before loading the template, I need to change the attribute values of certain elements such as id and name. However, reading the template object made it difficult for me to convert it to an HTML object so I can traverse and manipulate the DOM. After doing research and some experiments, I found the solution presented below on how to read the value of a Script template and be able to use jQuery methods to traverse and update the DOM elements. Sample Script Template To Load In A Page <script type= "text/html" id= "templateGroup" > <div name= 'divChildSkill_' class= "col-md-12" id= "divChildSkill_" > <div class= "col-md-12" > <div class= "col-md-6" > <div class= "col-md-4" > <label id= "anchorLabel" >...

XmlDataProvider With TwoWay Binding In WPF

Hello, Here's a simple example of two-way binding in WPF using XMLDataProvider. This post is taken from John Papa's example in MSDN magazine years ago but with minor errors. The XMLDataProvider markup has color values and is declared inside Window.Resources node. <Window.Resources> <XmlDataProvider x:Key= "MoreColors" > <x:XData> <colors xmlns= '' > <color name= "pink" /> <color name= "white" /> <color name= "black" /> <color name= "cyan" /> <color name= "gray" /> <color name= "magenta" /> </colors> </x:XData> </XmlDataProvider> </Window.Resources> The Textbox control's Text Text property binding has been set to TwoWay so when you enter a color name it will be added as a ListBox Item. <Grid> <StackPanel> <TextBlock Width= "248" Height= "24...

Bootstrap Table Footer Data Footer Formatter Not Computing Correctly On Multiple Columns

Image
Good Afternoon! I recently faced a minor bug in Bootstrap Table by Wenzhixin using a single data-footer-formatter for four columns. I expected that this will compute the column values but the expected result shows that all columns total are zero. Bootstrap Table <table id= "tblBillingReport" class= "TableBorderCollapse table-striped " data-toggle= "table" data-search= "true" data-show-columns= "false" data-advanced-search= "false" data-id-table= "advancedTable" data-show-export= "true" data-toolbar= "#toolbar" data-click-to- select = "true" data-unique-id= "objectID" data-cookie= "true" data-show-footer= "true" data-height= "700" data-cookie-id-table= "tblBillingReportID" > <thead> <tr style= "background-color: #FFFFFF;" > <th dat...

Donate