Posts

Showing posts from December, 2013

Donate

Append An Element To An Existing XML File (VB.NET)

Here's an example of appending a node to an xml file in VB.NET. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Dim doc As New XmlDocument() Dim file As New FileStream( "your_filename" , FileMode.Open) doc.Load(file) Try file.Close() file.Dispose() Dim root As XmlNode = doc.DocumentElement Dim el As XmlElement = doc.CreateElement( "Invoices" , "http://schemas.openxmlformats.org/package/2006/Invoices" ) el.SetAttribute( "Id" , "Test" ) doc.DocumentElement.AppendChild(el) root.InsertBefore(el, doc.DocumentElement.FirstChild) doc.Save( "your_filename" ) Catch ex As Exception Throw ex End Try Cheers!

Remove Extra Spacing In Between NumericUpDownExtender Default Buttons (ASP.NET Ajax)

Image
When integrating NumericUpDown Extender to your asp.net apps, there's a wide gap in between the up/down buttons as shown below: The trick to remove the extra space in between NumericUpDownExtender Default Buttons is to replace the doctype declaration in master page from: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> to: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> Note: This DTD contains all HTML elements and attributes, INCLUDING presentational and deprecated elements (like font) as described in w3. So, I believe there are presentational elements or deprecated elements incorporated into this extender. Reference: StackOverflow Cheers!

Append Text To Textfile In FTP Or SFTP Using SSH.NET

Hello, FtpWebRequest in .NET has few dozen bugs and some limitations when communicating to an FTP or perhaps an SFTP server. So, I decided to use SSH.NET which is a 3rd party .NET FTP client. You can use WinSCP or other existing FTP clients out there. Here's a sample code to append text to a textfile located in an FTP or SFTP Server. private void AppendTextToTextFile() { const int port = 22; const string host = "192.168.2.1" ; const string username = "greg" ; const string password = "testpassword" ; const string workingdirectory = "/root/files" ; const string uploadfile = @"D:\uploadfile.txt" ; Console.WriteLine( "Creating client and connecting" ); try { using ( var client = new SftpClient(host, port, username, password)) { client.Connect(); Console.WriteLine( "Con

Get All Records Before The Last Inserted Record In SQL Server T-SQL

In a scenario where you want to show all records before the latest injected record, one solution would be to get the latest date or perhaps tha latest primary key field. But, in cases where there is no primary key defined, there's another solution using Row_Number() in SQL Server. See the two queries below: -- option 1 select Production.Product.ProductID, Name as ID from Production.Product where (ProductID < ( Select MAX (ProductID) from Production.Product)) order by ProductID desc ; -- option 2 WITH ProductsView AS ( SELECT ProductID, Name, ROW_NUMBER() OVER ( ORDER BY ProductID) AS RowNumber From Production.Product ) SELECT ProductID, Name FROM ProductsView WHERE (RowNumber < ( select Max (RowNumber) from ProductsView)) order by ProductID desc ; Reference: Row_Number() in TSQL

Check If File Exists On FTP Server Using C# Or VB.NET

Method in VB.NET and C# here: File Exists on FTP Server

Predicate Wrapper Custom Class in VB.NET

Here's a custom predicate wrapper class I got from visual basic forums. I'll be converting and posting the C# equivalent for this. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 Public Delegate Function PredicateWrapperDelegate( Of T, A) _ ( ByVal item As T, ByVal argument As A) As Boolean Public Class PredicateWrapper ( Of T, A) Private _argument As A Private _wrapperDelegate As PredicateWrapperDelegate( Of T, A) Public Sub New( ByVal argument As A, _ ByVal wrapperDelegate As PredicateWrapperDelegate( Of T, A)) _argument = argument _wrapperDelegate = wrapperDelegate End Sub Private Function InnerPredicate( ByVal item As T) As Boolean Return _wrapperDelegate(item, _argument) End Function Public Shared Widening Operator CType ( _ ByVal wrapper As PredicateWrapper( Of T, A)) _ As Predicate( Of T) Return New Predicate( Of T

Read Excel 2010 64 Bit File On A 64 Bit Machine Using OleDB Provider In VB.NET

Hello, Here's the VB.NET Version of this post Read Excel 2010 64 bit file using OleDB Provider in C# on how to read Microsoft Excel 64 Bit File On a 64 bit maching using OleDB Provide and VB.NET as the language. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Option Strict On Option Infer On Imports System.Data Public Class Form1 Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase .Load Dim MyConnection As New OleDb.OleDbConnection( "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='c:\\temp\\test.xlsx';Extended Properties=Excel 12.0;" ) Dim DtSet As New DataSet() Dim MyCommand As New OleDb.OleDbDataAdapter( "select * from [Sheet1$]" , MyConnection) Try MyCommand.Fill(DtSet) DataGridView1.DataSource = DtSet.Tables(0) MyConnection.Close() Catch ex As ApplicationException Throw ex Finally End T

Read Excel 2010 64 Bit File On A 64 Bit Machine Using OleDB Provider In C#

Good afternoon! In the forums where I am a contributor, here's a tip on how to read an excel 2010 64/32 bit file using C#. The Operating System of my machine is Windows 8 64 bit. So, here are the steps. 1. Download AccessDatabaseEngine_x64.exe For 32 bit excel on windows 8 64 bit machines, download AccessDatabaseEngine.exe 2. Install it in my laptop. 3. Restart my laptop. 3. Change Active Config of Visual Studio Solution to Debug|Any CPU. For 32 bit excel, choose Debug|X86 4. Clean and Rebuild The Solution. Code: private void Form1_Load( object sender, EventArgs e) { try { System.Data.OleDbOleDbConnection MyConnection; System.DataDataSet DtSet; System.Data.OleDbOleDbDataAdapter MyCommand; MyConnection = new System.Data.OleDbOleDbConnection( "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='c:\\temp\\test.xlsx';Extended Properties=Excel 12.0;" ); MyCommand = new System.Data.OleDb

The Controls collection cannot be modified because the control contains code blocks(i.e.<% …%>) (ASP.NET HTML Editor Extender)

After adding an HTML Editor extender to my asp.net page, an error shows when rendering the page to the browser as stated which is the title of this post. I found the solution in asp.net forums which is to wrap aspx markup codes enclosed with <% %> using placeholder control. The code below is in my ASP.NET Master Page: <head runat= "server" > <title></title> <link href= "~/Styles/Site.css" rel= "stylesheet" type= "text/css" /> <asp:PlaceHolder Runat= "server" > <script src= '<%=Page.ResolveUrl("~/Scripts/jquery-1.4.1.min.js") %>' language= "javascript" type= "text/javascript" ></script> </asp:PlaceHolder> <asp:ContentPlaceHolder ID= "HeadContent" runat= "server" > </asp:ContentPlaceHolder> </head> Reference: Handling Ajax Extenders Error :)

ASP.NET jQuery $find() Not Working In Onclick() Event Of Radio Button

In an application where i want trigger the onclick event of radio button that has a $find() method, which will retrieve the radio button's value, the code below doesn't work. <input type= "radio" id= "rb1" name= "format" value= "format2" runat= "server" onclick= "$find('<%=dpe1.ClientID %>').populate(this.value);" /> d.m.y <input type= "radio" id= "rb2" name= "format" value= "format3" runat= "server" onclick= "$find('<%=dpe1.ClientID %>').populate(this.value);" /> y/m/d where dpe1 is a DynamicPopulateExtender Ajax Extender.The solution I made was to remove the populate logic and transfer it to a javascript function. Here's the revised code: //javascript code function rbFunction() { //$find('<%=dpe1.ClientID %>').populate($("input:radio:c

Donate