Asp. NET C # generates two-dimensional code

Source: Internet
Author: User

Asp. NET to write Web pages in C # language and generate two-dimensional code for the text you enter.

Tools/Materials
    • A computer with VS2010 or other version vs software installed.

1. New
    1. 1

      Create a new project (new project),

    2. 2

      Select Visual C #---->asp.net Web application and click OK.

    3. 3

      Right-click New Item,

    4. 4

      Select Web Form (Webform),

    5. 5

      Create a new folder image, which you want to use later.

      END
2, the basic layout of the page
    1. 1

      In the newly created WEBFORM1, switch to Design view, add TextBox Control and button control, change the button control's Text property (surface text) to "generate two-dimensional code", (Do not change, here for the sake of beautiful change).

    2. 2

      Add an image control, make the picture larger, or change the width and height properties of the image control, adjust the position of the control (or not, and adjust it slightly for aesthetics).

      END
3. Download the DLL file and reference
    1. 1

      Download ThoughtWorks.QRCode.dll to the desktop (other paths can also, as long as you know on the line), do not worry, the file is very small. This is the DLL file that generates the QR code. If it's less, it won't work.

    2. 2

      When the download is complete, add a reference (add Reference),

    3. 3

      Select the ThoughtWorks.QRCode.dll file that you just downloaded, add it in,

    4. 4

      In this step you can see the DLL files that have been added.

      END
4. Backstage Code
  1. 1

    Double-click the Generate two-dimensional code button to enter the background code, first add the namespace:

    Using System.Text;

    Using ThoughtWorks;

    Using Thoughtworks.qrcode;

    Using ThoughtWorks.QRCode.Codec;

    Using ThoughtWorks.QRCode.Codec.Data;

    Using System.Drawing;

  2. 2

    To invoke a method in a button click event:

    Create_two (this. TextBox1.Text);

    Add a method (note the location of the method):

    private void Create_two (string nr)

    {

    Bitmap BT;
    String encodestring = nr;
    Qrcodeencoder Qrcodeencoder = new Qrcodeencoder ();
    BT = Qrcodeencoder.encode (encodestring, Encoding.UTF8);
    string filename = DateTime.Now.ToString ("Yyyymmddhhmmss");
    String path = Server.MapPath ("~/image/") + filename + ". jpg";
    Response.Write (path);
    Bt. Save (path);
    This. Image1.imageurl = "~/image/" + filename + ". jpg";


    }

    END
5. Compiling and browsing
    1. 1

      Compilation (Rebuild),

    2. 2

      View in the browser,

    3. 3

      Enter the text you want, such as "OK" and click Generate QR code. Effect

      END
6. File Save
    1. Files are automatically saved to the local Project image folder after successful browsing

    2. You can also view it in the VS editor, notice that you want to show all the files to see, click "Show All" to display the file

      END
Precautions. measured at present only by the use of the browser "sweep" scan it, and other still can not be achieved, such as the reader can be achieved, hope to enlighten!
    • Here VS2010 Chinese version for example, corresponding to the other version and English are the same, careful on the line.

    • To first compile and then browse

Asp. NET C # generates two-dimensional code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.