Posts RSS Comments RSS 137 Posts and 271 Comments till now

Archive for the '.NET' Category

How to Traverse a Website Programmatically

Have you ever creating offline archive of a website that you like? Which “offline downloader” did you use? Hopefully this post will give you rough idea on how to traverse the website ( and do whatever you want to do with the content ). My idea of traversing a website represented in the following steps:

  1. Define the startup page
  2. Collect all hyper-links that have not been visited and put it into queue
  3. Do something with the content
  4. Dequeue a hyper-link and return to step 2
  5. Repeat until no more links in the queue.

I have build my own prototype that suit my needs. I might need further tweaks and improvements before releasing it to the public. My main goal would be adding functionality to define characteristics of the page that will be traversed in step 2, and functionality of what you can do with the content of the page. Stay tuned for further updates.

How to Install DotNetNuke

Apparently installing DotNetNuke is quite tricky. I did make a few mistakes which wasted a few minutes. So hopefully this post will save you from hassle.

  1. Get your Internet Information Server (IIS) up and running
    IIS is by default available on Windows 2000 all version, Windows XP Professional, Windows Server 2003. If you have Windows XP Home Edition, don’t worry. This hack should help to get IIS installed on Windows XP Home Edition. To confirm your installation click this HERE.
  2. Install .NET Framework 2.0
    Get your .NET Framework 2.0 HERE. The trick is always to get .NET Framework installed after your IIS confirmed up and running. You can’t do it the other way round. For most Windows XP installation, usually .NET Framework is already installed by default. If you happen to have such condition, you need to uninstall your .NET Framework, confirm that your IIS is up and running and then you proceed to install .NET Framework.
  3. Download DotNetNuke
    Although I recommended .NET Framework 2.0 at step 2, DotNetNuke older version is running on .NET Framework 1.1. So if you haven’t upgrade your .NET Framework to 2.0 and you don’t have intention to do so, download the DotNetNuke version 3.x. Otherwise, download version 4.x. The download page is HERE.
  4. Setup the Folder
    Extract the archive you download in Step 3. In this example we will assume the installation folder is C:\DotNetNuke. Right-click on C:\DotNetNuke folder, click Properties. On the General tab, make sure the Read-Only checkbox is not ticked. On the Security tab, add user “ASPNET” and give it Full Control access rights. You might want to add user “IUSER_YOURCOMPUTERNAME” (the IIS guest account) and give it non-Write access rights.
  5. Setup the Virtual Directory

    Open the IIS Management Console. You could do it by Start-Run-type “C:\Windows\System32\inetserv\iis.msc“-OK, or by Start-Run-type “compmgmt.msc“-OK continued by browsing to the IIS section. Right-click on the Default Web Site, New -> Virtual Directory. A wizard window will show up, click Next. Put DotNetNuke in the Alias text box, click Next. Browse to “C:\DotNetNuke”, click Next. Tick Read and Run Scripts only, click Next. Click Finish.
  6. Install Database
    Although DotNetNuke supports not only MS SQL Database, I have yet to research them. In this opportunity, I will only discuss about MS SQL. Hopefully someday I will have time to test DotNetNuke installation with other type of Databases and report it there. Okay, first you need to download your copy of MS SQL Express Edition. You can downloaded it HERE.
  7. Setup Database

    Open your SQL Server Management Studio (Start -> All Programs -> Microsof SQL Server 2005 -> SQL Server Management Studio). Click Connect. Above Database, Right-click -> New Database. Give the database a name, in this case we will name it MyDNN and click OK.


    Go to Security -> Logins. Above Logins, Right-click -> New Login. Type the Login Name –we will call it myDNNuser and then change the radio-button into SQL Server Authentication, and then type the password and confirm it, and then select the Default Database (i.e. MyDNN), and finally click OK.


    Go back to the MyDNN Database -> Security -> MyDNNuser -> Right-click -> Properties. Make sure db_owner on the “Schemas owned by this user is ticked”

  8. Edit Configuration File
    On the folder “C:\DotNetNuke” you will find web.config, edit it. If you could not find web.config, rename release.config into web.config. Look for a tag called <connectionStrings>. Inside it, comment the first child tag and uncomment the second one. Make sure you put the correct value in that tag. (i.e. value=”Server=YOUR_ComputerName\SQLEXPRESS; Database=myDNN; uid=myDNNuser; pwd=the_password;”). Do the same on the other tag called <appSettings>

After this you need to point your browser to “http://localhost/DotNetNuke/Install/install.aspx”. The installation should be automatic. Problems? Critics? Suggestions? Just drop your opinion on the comments. :-)

Create Drag-and-Drog File Path Locator

There are days when we actually need to get the full path location of a file. A quick example would be when you are adding entries into your Book Collector application. After downloads all information about the particular book you are adding, you are then adding the path of the e-Book into the ‘eBook Textbox’ entry. To fill up the entry, you can either browse for the file, or quickly copy and paste the full path location of the file. Usually the latter option is the fastest. Normally, you will do it in the following sequence:

  1. Open ‘Explorer
  2. Navigate the the folder, copy the folder name from address bar
  3. Return back to Book Collector, paste the folder name at the textbox
  4. Return again to Explorer, select the file, press F2/single-click, then copy the filename.
  5. Finally return to Book Collector to paste the filename.

This will become tedious and tiring once you have tens or hundreds entries to key in. So I came up with this solution. The logic of the application will be:

  1. Create a small, transparent floating box which is movable with mouse drag
  2. You can drag and drop a file to this floating box
  3. The full path of that file is copied to the Clipboard
  4. You can go back to Book Collector (or any other use) and paste the full path using Ctrl+V / right-click+paste

Lets tackle the requirement one by one. To create a small, transparent and floating box you need to set the following property:

  • AllowDrop: Change it into True to allow us drag-and-drop object to this Windows Form
  • BackColor: Change it into something cool (which is other than gray)
  • ControlBox: You only need the box. Set it into False
  • FormBorderStyle: Change it to anything but Sizeable.
  • Locked: Set it into True.
  • MaximizeBox: Set it into False
  • MinimizeBox: Set it into False
  • Opacity: This property regulate how transparent is your Windows Form.0% is completely invisible. 100% is not transparent at all. Set the value into around 50%
  • ShowIcon: Set it into False
  • ShowInTaskbar: Set it into False
  • TopMost: Set it into True

Finally modify the constructor to automatically set the size

 

public Form1()
{
   InitializeComponent();

   this.SuspendLayout();

   this.Size = new Size(35, 35);

   this.ResumeLayout();

}

To allow the window to be moved by dragging, you need to declare class-wide variable and create Event handlers

 

private bool isMouseDown = false; // to record whether window on dragging mode
private int oldX; //x-axis position when dragging start
private int oldY; //y-axis position when dragging start

// handle MouseDown Event
private void mouseDown(object sender, MouseEventArgs e)
{

   oldX = e.X;
   oldY = e.Y;
   isMouseDown = true;

}

// handle MouseMove Event
private void mouseMove(object sender, MouseEventArgs e)
{
   if (isMouseDown)
       this.Location = new Point(e.X+this.Location.X-oldX, e.Y+this.Location.Y-oldY);
}

// handle MouseUp Event
private void mouseUp(object sender, MouseEventArgs e)
{
   if (isMouseDown)
       isMouseDown = false;

}

// handle Keypress Event
// To close the program when user press ‘q’
private void Keypressed(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == ‘q’)
       this.Close();
}

The next step is to take care when a user Drop an object into the form

 

private void FmDragOver(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(DataFormats.FileDrop) || e.Data.GetDataPresent(DataFormats.StringFormat))
    {
       if ((e.AllowedEffect & DragDropEffects.Move) != 0)
       e.Effect = DragDropEffects.Move;
       if (((e.AllowedEffect & DragDropEffects.Copy) != 0) && ((e.KeyState & 0×08) != 0))
       e.Effect = DragDropEffects.Copy;
    }
}

private void FmDragDrop(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(DataFormats.FileDrop))
   {
      string[] astr = (string[])e.Data.GetData(DataFormats.FileDrop);
      Clipboard.SetText(astr[0]);
   }
}

Download the project here:

This solution has helped me save many minutes spend browsing, copy-pasting file’s full path. I hope it help you too.

Reference:
MSDN

Pages (6): « First ... « 3 4 5 [6]

Close
E-mail It
Socialized through Gregarious 42