Thursday, January 26, 2017

Error Method not found: '!!0[] System.Array.Empty()'. or Microsoft.VisualStudio.Web.PageInspector.Runtime

this error showing then try below code Method not found: '!!0[] System.Array.Empty()'. or Microsoft.VisualStudio.Web.PageInspector.Runtime
this work for me
<compilation targetFramework="4.5"> 
    <assemblies> 
        <remove assembly="Microsoft.VisualStudio.Web.PageInspector.Loader,
    Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </assemblies> 
</compilation>

Tuesday, March 1, 2016

iframe with external page not working in asp.net

iframe with external page not working asp.net then use object


<object type="text/html" data="http://www.google.co.in" style="width:100%; height:100%">

or


<script>$("#LoadUrl").load("http://www.google.co.in");</script>
<div id="LoadUrl"></div>

or 


Add this to header part of page or master page


<meta http-equiv="X-Frame-Options" content="allow" />


Add this to page body


  <iframe name="myIframe" id="myIframe" style="height: 500px; width: 100%;" runat="server" src="http://google.co.in/"></iframe>

Tuesday, February 23, 2016

Placing multiple markers on a Google Map

Placing multiple markers on a Google Map 

The HTML

<div id="map_wrapper">
    <div id="map_canvas" class="mapping"></div>
</div>

The CSS

#map_wrapper {
    height: 400px;
}

#map_canvas {
    width: 100%;
    height: 100%;
}

The JS

jQuery(function($) {
    // Asynchronously Load the map API
    var script = document.createElement('script');
    script.src = "http://maps.googleapis.com/maps/api/js?sensor=false&callback=initialize";
    document.body.appendChild(script);
});

function initialize() {
    var map;
    var bounds = new google.maps.LatLngBounds();
    var mapOptions = {
        mapTypeId: 'roadmap'
    };
                   
    // Display a map on the page
    map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
    map.setTilt(45);
       
    // Multiple Markers
    var markers = [
        ['London Eye, London', 51.503454,-0.119562],
        ['Palace of Westminster, London', 51.499633,-0.124755]
    ];
                       
    // Info Window Content
    var infoWindowContent = [
        ['<div class="info_content">' +
        '<h3>London Eye</h3>' +
        '<p>The London Eye is a giant Ferris wheel situated on the banks of the River Thames. The entire structure is 135 metres (443 ft) tall and the wheel has a diameter of 120 metres (394 ft).</p>' +        '</div>'],
        ['<div class="info_content">' +
        '<h3>Palace of Westminster</h3>' +
        '<p>The Palace of Westminster is the meeting place of the House of Commons and the House of Lords, the two houses of the Parliament of the United Kingdom. Commonly known as the Houses of Parliament after its tenants.</p>' +
        '</div>']
    ];
       
    // Display multiple markers on a map
    var infoWindow = new google.maps.InfoWindow(), marker, i;
   
    // Loop through our array of markers & place each one on the map 
    for( i = 0; i < markers.length; i++ ) {
        var position = new google.maps.LatLng(markers[i][1], markers[i][2]);
        bounds.extend(position);
        marker = new google.maps.Marker({
            position: position,
            map: map,
            title: markers[i][0]
        });
       
        // Allow each marker to have an info window   
        google.maps.event.addListener(marker, 'click', (function(marker, i) {
            return function() {
                infoWindow.setContent(infoWindowContent[i][0]);
                infoWindow.open(map, marker);
            }
        })(marker, i));

        // Automatically center the map fitting all markers on the screen
        map.fitBounds(bounds);
    }

    // Override our map zoom level once our fitBounds function runs (Make sure it only runs once)
    var boundsListener = google.maps.event.addListener((map), 'bounds_changed', function(event) {
        this.setZoom(14);
        google.maps.event.removeListener(boundsListener);
    });
   

}

wkhtmltopdf convert HTML document to Pdf

How do I use it?
  1. Download wkhtmltopdf.exe
  2. Create your HTML document that you want to convert into a PDF
  3. Run your HTML document through the tool.

Create Class WKHtmlToPdfClass.vb

Download wkhtmltopdf.exe and save in Folder
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Security
Imports System.Web
Imports System.Web.Hosting
Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Public Class WKHtmlToPdfClass
    Public Shared Function WKHtmlToPdf(ByVal url As String) As Byte()
        Dim fileName = " - "
        Dim wkhtmlDir = "C:\"
        Dim wkhtml = HttpContext.Current.Server.MapPath("~/FolderName/") & "wkhtmltopdf.exe"
        Dim p = New Process
        p.StartInfo.CreateNoWindow = True
        p.StartInfo.RedirectStandardOutput = True
        p.StartInfo.RedirectStandardError = True
        p.StartInfo.RedirectStandardInput = True
        p.StartInfo.UseShellExecute = False
        p.StartInfo.FileName = wkhtml
        p.StartInfo.WorkingDirectory = wkhtmlDir
        Dim switches As String = ""
        switches = (switches + "--print-media-type ")
        switches = (switches + "--margin-top 10mm --margin-bottom 10mm --margin-right 10mm --margin-left 10mm ")
        switches = (switches + "--page-size Letter ")
        p.StartInfo.Arguments = (switches + (" " _
                    + (url + (" " + fileName))))
        p.Start()
        'read output
        Dim buffer() As Byte = New Byte((32768) - 1) {}
        Dim file() As Byte
        Dim ms = New MemoryStream

        While True
            Dim read As Integer = p.StandardOutput.BaseStream.Read(buffer, 0, buffer.Length)
            If (read <= 0) Then
                Exit While
            End If

            ms.Write(buffer, 0, read)

        End While

        file = ms.ToArray
        ' wait or exit
        p.WaitForExit(60000)
        ' read the exit code, close process
        Dim returnCode As Integer = p.ExitCode
        p.Close()
        'Return (returnCode = 0)
        Return If(returnCode = 0, file, Nothing)
        'TODO: Warning!!!, inline IF is not supported ?
        'TODO: Warning!!!! NULL EXPRESSION DETECTED...

    End Function
   
End Class

Create default.aspx.vb
    Public Sub HTMLtoPDF()

        Dim url = "http://yoursite/FolderName/test.html"         
Dim file = WKHtmlToPdfClass.WKHtmlToPdf(url, TemplateName)
        If (Not (file) Is Nothing) Then
            Response.ContentType = "Application/pdf"
            Response.BinaryWrite(file)
            Response.End()
        End If
       
    End Sub


HTML Table to Save File in Asp.Net

    Public Sub SaveHTMLTabletoFile()
        Try

            Dim sb As StringBuilder = New StringBuilder()
            sb.Clear()
            sb.AppendLine("<table id='tbl1' border='0'>")
            sb.AppendLine("<tr>")
            sb.AppendLine("<td>Test 1</td>")
            sb.AppendLine("</tr>")
            sb.AppendLine("<tr>")
            sb.AppendLine("<td>Test 2</td>")
            sb.AppendLine("</tr>")
            sb.AppendLine("</table>")

            Dim path As String = Server.MapPath("download")
            If Not Directory.Exists(path) Then
                Directory.CreateDirectory(path)
            End If

            Dim strPath As String = Server.MapPath("download/test.html")

            Dim fStream As FileStream = File.Create(strPath)
            fStream.Close()
            Dim sWriter As New StreamWriter(strPath)
            sWriter.Write(sb)

            sWriter.Close()

        Catch ex As Exception
            Console.Write(ex.Message)
        End Try

    End Sub

File Transfer with FTP in Asp.Net

Create Page Default.aspx.vb
Write Method 
    Public Sub FTPFileTransfer()
        Dim objFtp As New FTP.FtpClass()
        Dim filePath As String = Server.MapPath("download/test.txt")
        objFtp.FtpUrl = "ftp://www.yoursite.com/FolderName"
        objFtp.Ftppassword = "Ftppassword"
        objFtp.Ftpusername = "Ftpusername"
        If objFtp.UploadFileToFTP(filePath) Then
            lblMessage.Text = "File has been uploaded on the server <br/> Check the uploaded file on http://yoursite.com/" & Path.GetFileName(filePath)
        Else
            Console.Write(objFtp.FtpException.Message)
        End If
    End Sub

Create Class FtpClass 
Write Method 


Imports System.Reflection
Imports System.Data
Imports System.IO
Imports System.Net
Imports System.Text

Public Class FtpClass 
    Public Property FtpUrl() As String
        Get
            Return m_FtpUrl
        End Get
        Set(value As String)
            m_FtpUrl = value
        End Set
    End Property
    Private m_FtpUrl As String
    Public Property Ftpusername() As String
        Get
            Return m_Ftpusername
        End Get
        Set(value As String)
            m_Ftpusername = value
        End Set
    End Property
    Private m_Ftpusername As String
    Public Property Ftppassword() As String
        Get
            Return m_Ftppassword
        End Get
        Set(value As String)
            m_Ftppassword = value
        End Set
    End Property
    Private m_Ftppassword As String
    Public Property FtpException() As Exception
        Get
            Return m_FtpException
        End Get
        Set(value As Exception)
            m_FtpException = value
        End Set
    End Property
    Private m_FtpException As Exception

    Public Function UploadFileToFTP(source As String) As Boolean
        Try

            Dim filename As String = Path.GetFileName(source)
            Dim ftpfullpath As String = FtpUrl
            ' +"/aceafrica";
            Dim ftp As FtpWebRequest = DirectCast(FtpWebRequest.Create(ftpfullpath & "/" & filename), FtpWebRequest)
            ftp.Credentials = New NetworkCredential(Ftpusername, Ftppassword)

            ftp.KeepAlive = True
            ftp.UseBinary = True
            ftp.Method = WebRequestMethods.Ftp.UploadFile

            Dim fs As FileStream = File.OpenRead(source)
            Dim buffer As Byte() = New Byte(fs.Length - 1) {}
            fs.Read(buffer, 0, buffer.Length)
            fs.Close()

            Dim ftpstream As Stream = ftp.GetRequestStream()
            ftpstream.Write(buffer, 0, buffer.Length)
            ftpstream.Close()
            Return True
        Catch ex As Exception
            FtpException = ex
            Return False
        End Try
    End Function

    Public Function GetFileList(Directory As String) As Boolean
        ' Public Function GetFileList(Directory As String) As List(Of String)
        Dim Files As New List(Of String)()
        Dim filename As String = Path.GetFileName(Directory)
        Dim ftpfullpath As String = FtpUrl
        Dim request As FtpWebRequest = DirectCast(WebRequest.Create(New Uri(ftpfullpath & "/" & filename)), FtpWebRequest)
        request.Method = WebRequestMethods.Ftp.ListDirectory

        request.Credentials = New NetworkCredential(Ftpusername, Ftppassword)
        ' Is this correct?
        ' request.Credentials = new NetworkCredential(ServerInfo.Username, ServerInfo.Password); // Or may be this one?
        request.UseBinary = False
        request.UsePassive = True

        Dim response As FtpWebResponse = DirectCast(request.GetResponse(), FtpWebResponse)

        Dim responseStream As Stream = response.GetResponseStream()
        Dim reader As New StreamReader(responseStream)
        Dim CurrentLine As String = reader.ReadLine()
        While Not String.IsNullOrEmpty(CurrentLine)
            Files.Add(CurrentLine)
            CurrentLine = reader.ReadLine()
        End While
        reader.Close()
        response.Close()
        Return True
    End Function
End Class




Adding Parameters to Commands

         Adding Parameters to Commands

          ' Method 1
            cmd.Parameters.Add("@ID", SqlDbType.Int)
            cmd.Parameters("@ID").Value = ID

            ' Method 2
            cmd.Parameters.Add("@ID", SqlDbType.Int).Value = ID

            ' Method 3
            cmd.Parameters.AddWithValue("@ID", ID)

            ' Method 4
            Dim param As SqlParameter = New SqlParameter
            param.ParameterName = "@ID"
            param.Value = ID
            cmd.Parameters.Add(param)