Thursday 31 October 2013

Convert SVG to PNG using svg.dll

      <div id="divsvg">

       <svg width="350" height="300"><defs></defs> ................</svg>

        </div>

<script type="text/javascript">

        var svg = $('#divsvg').html();

        document.getElementById("<%= hfdata.ClientID %>").value = encodeURIComponent(svg);

</script>

Code behind:

            var svg = hfdata.Value;

            var urldec = System.Web.HttpUtility.UrlDecode(svg);

             var svgpath = Server.MapPath("~") + "temp\\" + sessionid + ".svg";

            File.WriteAllText(svgpath, urldec);

            var sampleDoc = SvgDocument.Open(svgpath);

            sampleDoc.Draw().Save(Server.MapPath("~") + "\\App_Data\\tempImages\\" + sessionid + ".png");

Generate Pdf Using HTML file and iTextSharp

string contents = File.ReadAllText(HttpContext.Current.Server.MapPath("user.htm"));

string receiptString = this.GetReceiptString(contents);

string PdfPathwithName = Server.MapPath("~") + "\\temp\\" + DateTime.Now.ToString("ddMMyyyyhhmmss") + ".pdf";

Document document = new Document(PageSize.B4);

PdfWriter writer = PdfWriter.GetInstance(

document,

new FileStream(PdfPathwithName, FileMode.Create));

PdfDestination pdfDest = new PdfDestination(PdfDestination.XYZ, 0, document.PageSize.Height, 1.00f);

document.Open();

PdfAction action = PdfAction.GotoLocalPage(1, pdfDest, writer);

writer.SetOpenAction(action);

XMLWorkerFontProvider fontProvider = new XMLWorkerFontProvider();

CssAppliers cssAppliers = new CssAppliersImpl(fontProvider);

HtmlPipelineContext htmlContext = new HtmlPipelineContext(cssAppliers);

htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory());

ICSSResolver cssResolver = XMLWorkerHelper.GetInstance().GetDefaultCssResolver(true);

IPipeline pipeline = new CssResolverPipeline(cssResolver, new HtmlPipeline(htmlContext, new PdfWriterPipeline(document, writer)));

XMLWorker worker = new XMLWorker(pipeline, true);

XMLParser p = new XMLParser(true, worker, Encoding.UTF8);

TextReader reader = new StringReader(receiptString);

p.Parse(reader);

p.Flush();

document.Close();

document.Dispose();

Friday 26 July 2013

Get label value, Hidden field value using java script / jquery

var lat = document.getElementById("<%= hflat.ClientID %>").value;

           alert(lat);



            var mytit = document.getElementById("<%= lbltitle.ClientID %>").innerHTML;

           alert(mytit);

Wednesday 10 July 2013

call javascript function from page load c#.net / vb.net / asp.net


call javascript function from page load c#.net / vb.net

c#.net:

Page.ClientScript.RegisterStartupScript(this.GetType(), "Call my function", "Myfunction();", true);

vb.net

Page.ClientScript.RegisterStartupScript(Me.[GetType](), "Call my function", 
"Myfunction();", True)

Friday 5 July 2013

Get location (Latitude & Longitude) for given address in ASP.NET using google api

Get latitude and longitude using C# for given location

C#.NET:

public static List<string> GetLatLng(string address)
{
 dynamic requestUri = string.Format("http://maps.googleapis.com/maps/api/geocode/xml?address={0}&sensor=true", Uri.EscapeDataString(address));
 dynamic request = WebRequest.Create(requestUri);
 dynamic response = request.GetResponse();
 dynamic xdoc = XDocument.Load(response.GetResponseStream());
 dynamic latLngArray = new List<string>();
 dynamic xElement = xdoc.Element("GeocodeResponse");
 if (xElement != null) {
  dynamic result = xElement.Element("result");
  if (result != null) {
   dynamic element = result.Element("geometry");
   if (element != null) {
    dynamic locationElement = element.Element("location");
    if (locationElement != null) {
     dynamic xElement1 = locationElement.Element("lat");
     if (xElement1 != null) {
      dynamic lat = xElement1.Value;
      latLngArray.Add(lat);
     }
     dynamic element1 = locationElement.Element("lng");
     if (element1 != null) {
      dynamic lng = element1.Value;
      latLngArray.Add(lng);
     }
    }
   }
  }
 }
 return latLngArray;
}

add multple locations in google map using asp.net c#.net/ vb.net

here shows multiple locations adding in google map using java script / jquery in Asp.net, c#.net, vb.net

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript">
    var markers = [
    <asp:Repeater ID="rptMarkers" runat="server">
    <ItemTemplate>
             {
                "title": '<%# Eval("title") %>',
                "lat": '<%# Eval("lat") %>',
                "lng": '<%# Eval("lng") %>',
                "description": '<b><%# Eval("title") %></b> <br><%# Eval("address") %>'
            }
    </ItemTemplate>
    <SeparatorTemplate>
        ,
    </SeparatorTemplate>
    </asp:Repeater>
    ];
    </script>

 <script type="text/javascript">

        window.onload = function () {
            Dataload();
        }
        function Dataload() {
            var mapOptions = {
                center: new google.maps.LatLng(markers[0].lat, markers[0].lng),
                zoom: 13,
                disableDefaultUI: true,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            var infoWindow = new google.maps.InfoWindow();
            var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
            for (i = 0; i < markers.length; i++) {
                var data = markers[i]
                var myLatlng = new google.maps.LatLng(data.lat, data.lng);
                var marker = new google.maps.Marker({
                    position: myLatlng,
                    map: map,
                    title: data.title
                });
                (function (marker, data) {
                    google.maps.event.addListener(marker, "click", function (e) {
                        infoWindow.setContent(data.description);
                        infoWindow.open(map, marker);
                    });
                })(marker, data);
            }
        }
    </script>


Retrieve data from visible false BoundField of Gridview

get value of visible false boundfield in gridview Asp.net

<style type="text/css">
     .hidden
     {
         display:none;
     }
</style>

<asp:BoundField DataField="ReportId" HeaderText="RId"  >
    <ItemStyle CssClass="hidden"/>
</asp:BoundField>

Gridview row hover alert rowindex

on hover Gridview row, show row index as alert message

write onmouseover on rowdatabound

protected void mygridview_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex != -1)
{
e.Row.Attributes["onmouseover"] = "showContents('" + (e.Row.RowIndex + 1) + "')";
}

}

 <script type="text/javascript">
        function showContents(rowIndex) {

            var gv = <%= mygridview.ClientID %>;
            var rowElement = gv.rows[rowIndex];
            var title = rowElement.cells[0].innerHTML;
            alert(rowIndex + ',' + title);

}

Wednesday 26 June 2013

select from table distinct column

SELECT * FROM TABLE WITH DISTINCT COLUMN
---------------------------------------------------------------

SELECT * FROM [TABLE NAME]
WHERE [ID] IN (
  SELECT MIN([ID]) FROM [TABLE NAME] GROUP BY [DISTINCT COLUMN NAME])

Example:

       SELECT FROM [SKILLS] WHERE [ID] IN
       (
      SELECT MIN([ID]) FROM [SKILLS] GROUP BY [SKILL NAME]
       )

Friday 21 June 2013

string split using jquery / java script

var a = "one,two,three".split(",") // Delimiter is a string
for (var i = 0; i < a.length; i++)
{
alert(a[i])
}

var b = "1+2=3".split(/[+=]/) // Delimiter is a regular expression
for (var i = 0; i < b.length; i++)
{
alert(b[i])
}

Friday 14 June 2013

500 Internal Server Error” when adding HttpModule in my Web.config

use the following new module syntax made for IIS7 (godaddy is using IIS7 for windows hosting)
<configuration>
   <system.webServer>
      <modules>
         <add name="Header" type="Contoso.ShoppingCart.Header"/>
      </modules>
   </system.webServer>
</configuration>
here details about module tag  

Tuesday 12 March 2013

Login failed for user 'IIS APPPOOL\ASP.NET v4.0'

Set Identity : LocalSystem
enter image description here

You can change the ApplicationPoolIdentity from IIS7 -> Application Pools -> Advanced Settings.

AdvancedSettings

Friday 15 February 2013

How to Draw Text on an Image c#


Bitmap myBitmap = new Bitmap("C:\\myImage.jpg");
Graphics g = Graphics.FromImage(myBitmap);
StringFormat strFormat = new StringFormat();
strFormat.Alignment = StringAlignment.Center;
strFormat.LineAlignment = StringAlignment.Center;
g.DrawString("My\nText", new Font("Tahoma", 20), Brushes.White,
    new RectangleF(0, 0, 500, 500), strFormat);
myBitmap.Save("C:\\myImage1.jpg");


Highlight Asp.net Gridview Rows on MouseOver in jQuery


<script type="text/javascript">
$(document).ready(function() {
$('#gvrecords tr:has(td)').mouseover(function() {
$(this).addClass('highlightRow');
});
$('#gvrecords tr').mouseout(function() {
$(this).removeClass('highlightRow');
})
})
</script>

<style type="text/css">
.highlightRow
{
background-color:#FFCC00;
text-decoration:underline;
cursor:pointer;
}
</style>

$('#gvrecords tr:has(td)').mouseover(function() {
By using this we are identifying row tr with td and applying css style for gridview. Instead of this we can write the code like this
$('#gvrecords tr').mouseover(function() {
But above code will apply css style for gridview header also for that reason we written above code to identity and apply css style for row tr with td

Monday 11 February 2013

Blinking text using jQuery



<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Add blinking effect to text in jQuery</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function() {
blinkeffect('#txtblnk');
})
function blinkeffect(selector) {
$(selector).fadeOut('slow'function() {
$(this).fadeIn('slow'function() {
blinkeffect(this);
});
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="txtblnk"> <p><strong><font color="red">Welcome to dotnetdatastuff.blogspot.in</font></strong></p> </div>
</form>
</body>
</html>

Random Color Generator in JavaScript



<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Generate Random Colors using javascript</title>
<script type="text/javascript">
// Run function for every second of timer
setInterval(rgbcolors, 1000);
function rgbcolors() {
// rgb string generation
var col = "rgb("
+ Math.floor(Math.random() * 255) + ","
+ Math.floor(Math.random() * 255) + ","
+ Math.floor(Math.random() * 255) + ")";
//change the text color with the new random color
document.getElementById("divstyle").style.color = col;
}
</script>
</head>s
<body>
<form id="form1" runat="server" >
<div id="divstyle" style="font:bold 24px verdana">http://dotnetdatastuff.blogspot.in/</div>
</form>
</body>
</html>

Monday 4 February 2013

jQuery Get Current Page URL

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Get Curent Page Url using jQuery in Asp.net</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function () {
var url = $(location).attr('href');
var title= $(this).attr('title');
$('#spn_title').html('<strong>' + title + '</strong>');
$('#spn_url').html('<strong>' + url + '</strong>');
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<p>Current page URL: <span id="spn_url"></span>.</p>
<p>Current page title: <span id="spn_title"></span>.</p>
</div>
</form>
</body>
</html>

Convert SVG to PNG using svg.dll

      <div id="divsvg">        <svg width="350" height="300"><defs></defs> ............