Thursday, 1 August 2013

How to parse json in classic asp

aspjson.asp  download from this link

[INPUT]

{
“firstName”: “John”,
“lastName” : “Smith”,
“age” : 25,
“address” :
{
“streetAddress”: “21 2nd Street”,
“city” : “New York”,
“state” : “NY”,
“postalCode” : “10021″
},
“phoneNumber”:
[
{
"type" : "home",
"number": "212 555-1234"
},
{
"type" : "fax",
"number": "646 555-4567"
}
]
}

<!–#include virtual=”/aspJSON.asp” –>

<%
Set oJSON = New aspJSON

‘Load JSON string
oJSON.loadJSON(jsonstring)

‘Get single value
Response.Write oJSON.data(“firstName”) & “<br>”

‘Loop through collection
For Each subItem In oJSON.data(“address”)
Response.Write subItem & “: ” & _
oJSON.data(“address”).item(subItem) & “<br>”
Next

‘Update/Add value
oJSON.data(“firstName”) = “James”

‘Return the object
Response.Write oJSON.JSONoutput()
%>

Friday, 19 July 2013

How do I put Google Adsense ads on website

Please use this code and change google_ad_client value

<script type="text/javascript">
google_ad_client = "AIzaSyDFsldP-wTV6jdR4D-MxQojl831HGXAhVI";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
google_color_border = "FFFFFF";
google_color_bg = "0000FF";
google_color_link = "FFFFFF";
google_color_text = "000000";
google_color_url = "008000";
</script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

How to Remove Restricted User in SQL Server

execute this query
Use [dbname]
ALTER DATABASE [dbname] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
ALTER DATABASE [dbname] SET MULTI_USER
GO

Friday, 2 November 2012

How to add bookmark on pdf file using itextsharp


 Document document = new Document(PageSize.A4, 50, 50, 25, 25);

            // Create a new PdfWriter object, specifying the output stream
         
            PdfWriter.GetInstance(document, new FileStream(Server.MapPath(“MyFirstPDF.pdf”), FileMode.Create));

            Chapter chapter1 = new Chapter(new Paragraph(“This is Chapter 1″), 1);
            Section section1 = chapter1.AddSection(20f, “Section 1.1″, 2);
            Section section2 = chapter1.AddSection(20f, “Section 1.2″, 2);
            Section subsection1 = section2.AddSection(20f, “Subsection 1.2.1″, 3);
            Section subsection2 = section2.AddSection(20f, “Subsection 1.2.2″, 3);
            Section subsubsection = subsection2.AddSection(20f, “Sub Subsection 1.2.2.1″, 4);
            Chapter chapter2 = new Chapter(new Paragraph(“This is Chapter 2″), 1);
            Section section3 = chapter2.AddSection(“Section 2.1″, 2);
            Section subsection3 = section3.AddSection(“Subsection 2.1.1″, 3);
            Section section4 = chapter2.AddSection(“Section 2.2″, 2);
            chapter1.BookmarkTitle = “Changed Title”;
            chapter1.BookmarkOpen = true;
            chapter2.BookmarkOpen = true;
            document.Add(chapter1);
            document.Add(chapter2);
            // Add the Paragraph object to the doc

How to Share a Link on Twitter


Please click on image and check

please use this code

<img id="ctl00_ctl00_ShareLink1_imgTwitter" border="0" onclick="ShareName('twitter')" src="images/icons/Twitter.png" alt="Twitter" style="border-width:0px;">
:
<script type="text/javascript"> var path = ""; var text = ""; function ShareName(title) { if (title == "twitter") { path = "http://twitter.com/share?url="; text = "&text="; ShareLink(path, text); } } function ShareLink(path, text) { var title = document.title; title = encodeString(title); var url = document.location; url = encodeString(url); var link = url + text + title; link = path + link; window.open(link); return false; } function encodeString(text) { var output = escape(text); output = output.replace("+", "%2B"); output = output.replace("/", "%2F"); return output; } </script>

Monday, 29 October 2012

Online Credit Card Transaction in ASP.NET Using PayPal Pro / dodirect

  string strUsername = "api user name";
            string strPassword = "pasword";
            string strSignature = "signature";
            string strCredentials = "USER=" + strUsername + "&PWD=" + strPassword + "&SIGNATURE=" + strSignature;

            string strNVPSandboxServer = "https://api-3t.sandbox.paypal.com/nvp";
            string strAPIVersion = "50.0";
       
            string strNVP = strCredentials + "&METHOD=DoDirectPayment" +
            "&CREDITCARDTYPE=" + "credit card type"+
            "&ACCT=" + "credit card number" +
            "&EXPDATE=" + "expire date" +
            "&CVV2=" + "cvv number"+
            "&AMT=" + "100" +
            "&FIRSTNAME=" + "Gopal" +
            "&LASTNAME=" + "Singh"+
            "&IPADDRESS= ip address" +
            "&STREET=" + "street" +
            "&CITY=" + "city"+
            "&STATE=" +"state"+
            "&COUNTRY=" + "contry" +
            "&ZIP=" +"1234" + "" +
            "&CURRENCYCODE=GBP" +
            "&PAYMENTACTION=Sale" +
            "&VERSION=" + strAPIVersion;


            try
            {
                //Create web request and web response objects, make sure you using the correct server (sandbox/live)
                HttpWebRequest wrWebRequest = (HttpWebRequest)WebRequest.Create(strNVPSandboxServer);
                wrWebRequest.Method = "POST";
                StreamWriter requestWriter = new StreamWriter(wrWebRequest.GetRequestStream());
                requestWriter.Write(strNVP);
                requestWriter.Close();

                // Get the response.
                HttpWebResponse hwrWebResponse = (HttpWebResponse)wrWebRequest.GetResponse();
                StreamReader responseReader = new StreamReader(wrWebRequest.GetResponse().GetResponseStream());

                //and read the response
                string responseData = responseReader.ReadToEnd();
                responseReader.Close();

                string result = Server.UrlDecode(responseData);

                string[] arrResult = result.Split('&');
                Hashtable htResponse = new Hashtable();
                string[] responseItemArray;
                foreach (string responseItem in arrResult)
                {
                    responseItemArray = responseItem.Split('=');
                    htResponse.Add(responseItemArray[0], responseItemArray[1]);
                }

                string strAck = htResponse["ACK"].ToString();
                Response.Write(strAck);

                if (strAck == "Success" || strAck == "SuccessWithWarning")
                {
                    string strAmt = htResponse["AMT"].ToString();
                    string strCcy = htResponse["CURRENCYCODE"].ToString();
                    string strTransactionID = htResponse["TRANSACTIONID"].ToString();
                    string strSuccess = "Thank you, your order for: $" + strAmt + " " + strCcy + " has been processed.";


                }
                else
                {
                    string strErr = "Error: " + htResponse["L_LONGMESSAGE0"].ToString();
                    string strErrcode = "Error code: " + htResponse["L_ERRORCODE0"].ToString();
           

                }
            }
            catch (Exception ex)
            {
                // do something to catch the error, like write to a log file.
                // Response.Write("error processing");
                //  Response.End();
             
            }

Friday, 12 October 2012

convert text file into csv file in c#


  try
            {

             
                OpenFileDialog dialog = new OpenFileDialog();
                dialog.Title = "Open file as...";
                dialog.Filter = "txt files (*.txt)|*.txt";
                dialog.RestoreDirectory = true;

                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    string csvFileName = dialog.FileName;
                    //get the user to specify the                  
                    TextReader reader = new StreamReader(csvFileName);
                    string a = reader.ReadToEnd();

                    char[] array = a.ToCharArray();

                    reader.Close();
                    MessageBox.Show("File Converted! Please save");

                    SaveFileDialog dialogSave = new SaveFileDialog();
                    dialogSave.Title = "Save file as...";
                    dialogSave.Filter = "CSV files (*.csv)|*.csv";
                    dialogSave.RestoreDirectory = true;

                    if (dialogSave.ShowDialog() == DialogResult.OK)
                    {
                        string saveFile = dialogSave.FileName;
                        //get the user to specify the                



                        FileStream aFile = new FileStream(saveFile, FileMode.OpenOrCreate);

                    StreamWriter sw = new StreamWriter(aFile);

                    for (int i = 0; i < array.Length; i++)
                    {

                        if (array[i] == '\n' && array[i] == '\r')

                            sw.WriteLine();

                        else

                            sw.Write(a[i] + ",");

                    }

                    sw.Close();
                    }
                 
                }



            }
            catch (Exception ex)
            {
                MessageBox.Show("There was an error creating the download report:" + ex.Message);

            }