Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i am 16 years old and my english isnt very well . excuse me !

this code can get some link in rich textbox and then save the contents of links in txt files !

i want my program read links from a table in sql server database and also save contents of links in another table . contents of every link in a record .

can u please help me ?!

every link in my table have an id . like this :
id adress
10200 www.test.com/test1.html
10201 www.test.com/test2.html

and this is content of a link : 123,234,567,1,44,55,66,77

i need first and second number to save in a table .



my code is :

C#
public void StartThreads()
        {
           
            List source = new List();
            source.AddRange(this.rich1.Lines);
            Parallel.ForEach(source, new Action(this.ProcessUrl));
                           
        }
        private void ProcessUrl(string url)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
            request.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)";
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Random random = new Random();
            using (Stream stream = System.IO.File.OpenWrite(Globals.c++ + ".txt"))

            {
                using (Stream stream2 = response.GetResponseStream())
                {
                    stream2.CopyTo(stream);
                }
            }
        }

        private void rich1_TextChanged(object sender, EventArgs e)
        {
            this.lbl1.Text = this.rich1.Lines.Count().ToString();
        }
        public static class Globals
        {
            public static int c = 1;
        }
Posted
Updated 21-Sep-14 19:47pm
v2
Comments
George Jonsson 22-Sep-14 3:45am    
Well how much do you know about programming in general and databases in particular?
Do you have a database for this purpose yet?
itman2 22-Sep-14 6:01am    
yes I create a database .
a table for links with 3 field : id - name - address

and a table for data with 3 field : id - no1 - no2

my program must read links from LINK Table and save in DATA Table

I am beginner in programing !

1 solution

Not exactly sure what you are trying to do, so this only answer a part of your question.

If you want the first two numbers from the string
C#
string link = "123,234,567,1,44,55,66,77"

you can use regular expressions. See this link for more info: Regular Expressions Tutorial[^]

In this case it is a pretty easy regex.
C#
// Add this at the top of your file
using System.Text.RegularExpressions;

int no1 = 0;
int no2 = 0;
// This expression will take the first two numbers in the string
Regex rx = new Regex(@"(?<no1>\d+)\s*,\s*(?<no2>\d+)");
Match m = rx.Match(link);
if (m.Success)
{
    no1 = int.Parse(m.Groups["no1"].Value);
    no2 = int.Parse(m.Groups["no2"].Value);
    // Now you can add these values in your data tables
}
else
{
    // Well, what do you want to do here.
}


You can find many sources for reading and writing data to and from a database. Just use your favorite search engine.
Here are some examples:

Beginners guide to accessing SQL Server through C#[^]

W3 Schools - SQL Tutorial[^]

MSDN - SqlDataAdapter Class[^]

Dot Net Pearls - C# SqlDataAdapter[^]
 
Share this answer
 
v3
Comments
itman2 22-Sep-14 7:41am    
thanks a lot Mr jonsson .
its useful ! I think I can write cod for save no1,no2 ( wow ! I can !! )

just 1 question : how can I read links from table? my program read links from rich textbox . I paste for example 10 link in rich textbox and thread save them in txt files. but I want read links from my table . howcan I change this cod ?
public void StartThreads()
{

List source = new List();
source.AddRange(this.rich1.Lines);
Parallel.ForEach(source, new Action(this.ProcessUrl));
George Jonsson 22-Sep-14 21:01pm    
You should learn to walk before you start running. Skip the threading and parallel thingys in the beginning.
See the links I added in my answer or how to access a database.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900