Source code for a simple backlinking app

shedboy

Make Money Online
Joined
Jul 31, 2009
Messages
39
Reaction score
0
Points
6
I though we could do with some more code examples

This is basically the source code for a little app I programmed for myself. Its similar to the masses of those backlinkng apps that are out there

Note

The url to be submitted is in const string url = "myurl.net"; realistically this would be better to be a text box that accepts a url and stores the reults in a variable

Sources.txt contains a list of 'backlink sites' in the format at http://whois.domaintools.com/{website}

I'll try and make some improvements at some time and zip up the project and exe

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.IO;
using System.Net;
using System.Text;
using System.Windows.Forms;

namespace Backlinker
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            const string f = "sources.txt";
            const string url = "myurl.net";
            const string placeholder = "{website}";
            string backurl, submiturl;

            List<string> lines = new List<string>();
            using (StreamReader r = new StreamReader(f))
            {
                string line;
                while ((line = r.ReadLine()) != null)
                {
                    lines.Add(line);
                }
            }

            int count = lines.Count();
            int i = 0;
            FileStream MyFile = new FileStream("report.txt", FileMode.OpenOrCreate);
            StreamWriter MyWriter = new StreamWriter(MyFile);
            while (i <= count - 1)
            {

                //get the backlink site from the list
                backurl = lines[i];
                //replace the placeholder text with your url
                submiturl = backurl.Replace(placeholder, url);
                //catch all exceptions
                try
                {
                    WebRequest request = WebRequest.Create(submiturl);
                    // Sends the HttpWebRequest and waits for a response.
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        MyWriter.Write(submiturl + " successfully submitted");
                        MyWriter.Write(MyWriter.NewLine);
                    }
                    else
                    {
                        MessageBox.Show(submiturl + " Failed");
                        MyWriter.Write(MyWriter.NewLine);
                    }
                    response.Close();

                }
                catch (WebException we)
                {
                    MyWriter.Write("\r\nWebException Raised. The following error occured : {0}", we.Status);
                    MyWriter.Write(MyWriter.NewLine);
                }
                catch (Exception ex)
                {
                    MyWriter.Write("\nThe following Exception was raised : {0}", ex.Message);
                    MyWriter.Write(MyWriter.NewLine);
                }

                i++;
            }
            MessageBox.Show("Submitted to all Backlink sites");
            MyWriter.Close();
            MyFile.Close();
        }
    }
}
 

sammib

Make Money Online
Joined
Jun 16, 2010
Messages
51
Reaction score
0
Points
0
Age
50
Who.is is always there. It is the sourse to find site owners and info about all websites and availability.
 

adonic

Make Money Online
Joined
Apr 5, 2010
Messages
1
Reaction score
0
Points
0
thanks for sharing your source code