Asp.net Delete news and delete image design ideas

Source: Internet
Author: User
My advertisement unit. Please click here. Thank you!

Recently, I encountered a problem where the text and text are mixed in the news publishing function. However, when I delete the news, the pictures in the news are not deleted at the same time, because most HTML editors only support uploading images, which can be used to browse images on the server, but the effect is poor, how can they retrieve pictures in news, then, what about "articles" based on these images?

Through data collection, I have summarized a set of ideas for reference only, as shown below:

First, design the news table (I only select the key fields), ID, title, details, publishtime, publishman, newsimg (This field records the pictures in the news, the field length is longer, because it records the complete URL of the image. Of course, you can only save the image name, but in some cases, the image cannot be displayed)

The database is well designed, and then the image is taken. Here I use a regular expression to retrieve it.

// Return all the pictures in the news, separated by | Public String mygetimgurl (string text) {stringbuilder STR = new stringbuilder (); string PAT = @ "] * \ s * SRC \ s * = \ s * ([']?) (? <URL> \ s + )'? [^>] *> "; RegEx r = new RegEx (Pat, regexoptions. compiled); match M = R. match (text. tolower (); While (M. success) {group G = m. groups [2]; Str. append (g ). append ("|"); // G is the complete URL of the image. M = m. nextmatch ();} return Str. tostring (). replace ("\"",""). trimend ('|');} // insert news protected void button#click (Object sender, eventargs e) {cj_dboperater.cj.sqlconn_str = "Server = localhost; database = piclinktonews; uid = sa; pwd = ovenjackchain "; string STR =" insert into news values ('{0}', '{1}', '{2}', '{3 }', '{4}') "; // txtcontent. text is the content of the HTML editor, which is in the HTML format of cj_dboperater.cj. SQL _executenonquery (string. format (STR, txttitle. text, txtcontent. text, datetime. now. tostring (), "admin", mygetimgurl (this. txtcontent. text); // insert successful}

Now we have inserted a piece of news and put the image URL in the news into the newsimgs field.

The next thing is easy to do.

For example, if I want to make a flash image scroll effect, the image is a news image. clicking an image will jump to the news, then the focus is how to retrieve the image.

It's easy, because we have put the image in the newsimgs field, and we only need SQL statements.

 

DataTable dt = CJ_DBOperater.CJ.SQL_ReturnDataTable("select top 4 NewsImgs from news where NewsImgs!=''");for (int i = 0; i < dt.Rows.Count; i++){if (dt.Rows[i][0].ToString().Contains('|'))Response.Write(dt.Rows[i][0].ToString().Substring(0, dt.Rows[i][0].ToString().IndexOf('|')) + "<br />");elseResponse.Write(dt.Rows[i][0].ToString()+"<br />");}

// Here, only the first image is taken for each news article (if there is an image in the News)

OK.

The image is taken out, so it is OK to delete the news and delete the picture.

Of course, if you only delete news and images, you do not need the newsimgs field.

Source code download: http://download.csdn.net/source/2119062

Related Article

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.