|
Hi, I was reading how to create a program that crawls website data. one of the example I found was http://www.codeproject.com/KB/IP/Crawler.aspx
but I dont have much resource to crawl everything. In a ideal e-shops you have product page and product details page. what I would like to do is crawl each product page and product details page and only write data that interests me to my database. e.g. product name, product price, etc etc.
could anyone point me to right direction?
Thank you
|
|
|
|
|
So you have used someones article to crawl some web sites, this is good. Now you need to customise the article to meet your needs, so inspect the data as it is crawled and decide what to do with it.
Something along the lines of if it is a product then turn a store flag on and write the data to the database, identify the token that denotes the end of the product information and turn off the store flag.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I am having a little problem. I can get the ip address and hostname and such of my local machine, but what I am trying to do is get the ip address range on the LAN from my local address.
So if my ip is:
10.10.50.2
and the subnet is: 255.255.0.0
How do I get C# to give me the start value (which would be 10.10.0.1) and the end value (which would be 10.10.255.255)?
I don't want to have to have this entered in and want it to go off the local computers information. I can already get the ip address and the subnet.. I'm not unsure how to get the start and end from that information
|
|
|
|
|
Jacob Dixon wrote: How do I get C# to give me the start value (which would be 10.10.0.1) and the end value (which would be 10.10.255.255)?
You have to write the code for that. There is no builtin function to do the math for you. A little Google for "how to calculate ip address range" brings up plenty of results.[^]
|
|
|
|
|
Thanks.. first I was searching for the wrong things.. like what I was typing in.. but I got something that works for me after modifying it
static string GetRange(IPAddress address, IPAddress subnetMask)
{
IPAddress ip = address;
byte[] ipBytes = ip.GetAddressBytes();
byte[] maskBytes = subnetMask.GetAddressBytes();
byte[] startIPBytes = new byte[ipBytes.Length];
byte[] endIPBytes = new byte[ipBytes.Length];
for (int i = 0; i < ipBytes.Length; i++)
{
startIPBytes[i] = (byte)(ipBytes[i] & maskBytes[i]);
endIPBytes[i] = (byte)(ipBytes[i] | ~maskBytes[i]);
}
IPAddress startIP = new IPAddress(startIPBytes);
IPAddress endIP = new IPAddress(endIPBytes);
return startIP.ToString() + " -- " + endIP.ToString();
}
|
|
|
|
|
So you need to thank Dave with a 5 for giving you some of his Google mojo.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi,
I'm trying to get all the files from directory that ends with *.txt only.
The problem is, when i'm doing:
string[] filePaths = Directory.GetFiles(@"C:\MyDir\", "*.txt");
i get also the path.
How can i get only the filename?
(at the end i have to get a string[] because i need to use it as DataSource)
|
|
|
|
|
Example:
string fileName = @"C:\mydir\myfile.txt";<br />
string result;<br />
result = Path.GetFileName(fileName);
Regards.
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.aktualiteti.com
|
|
|
|
|
tamir901 wrote: i need to use it as DataSource
For a Control? What type?
Have you tried this:
System.IO.FileInfo[] fi = (new System.IO.DirectoryInfo ( "C:\\" )).GetFiles ( "*.txt" ) ;
listBox1.DataSource = fi ;
comboBox1.DataSource = fi ;
checkedListBox1.Items.AddRange ( fi ) ;
domainUpDown1.Items.AddRange ( fi ) ;
I prefer using FileInfo rather than string.
|
|
|
|
|
Thanks...
|
|
|
|
|
I'm a long time VB addict, and I am finally making the switch, and have a quick question. When you're in the code view in VB and you open the drop-down box on the right, you get all the options for that control, so lets say you were in form1_load and clicked the drop down, you would see every available option for form1_whatever. Where the heck is that in C#? I'm going to have to keep VB open just to see the options... hahaha.
Thanks in advance!
|
|
|
|
|
You mean Propety Windows?
You go to view and Select Property Window or Right-Click on any control in Design mode and select Properties. After that you can dock with control
|
|
|
|
|
Nah, like form1_leave form1_click form1.ondragdrop etc, all the events that can be handled in your code...
|
|
|
|
|
ahhh i found it, sorta. Thanks
Theres an events "tab" in the properties window... wierd
|
|
|
|
|
|
You'll find the same thing in VB.NET as well.
What you talking about is specific to the VB.NET code editor. It doesn't show up in the C# version.
|
|
|
|
|
Acording to tutorial (A book: GDI+ Custom Controls With Visual CSharp 2005)I am reading, i have created Custom Control that is divered from Control.
I have overriden OnPaint event, and everytime i put base.OnPaint(e) into event, my IDE and app crashes. IDE crashed due to tempting to render a custom control. I am using VS 2008 SP1 and .NET framework 3.5 SP1.
Why does this happen? Is it required to put inside when diverting from Control class)
Edit: Found the problem. The problem was that I used base.OnPaint() inside event function. I needed to ovridde OnPaint
modified on Sunday, December 6, 2009 2:09 PM
|
|
|
|
|
OnPaint() method actually raises the Paint event. By calling OnPaint() from a method bound to the Paint event, you actually set up an infinite loop causing a stack overflow that crashed the IDE.
|
|
|
|
|
Hello,
I'm developing an app that localize WPF applications but When I try to serialize a class that contains a BAMLLOCALIZATIONDICTIONARY serialization failed because this class do not allow serialization.
Is there any way to serialize this class?
Thanks.
Dad
|
|
|
|
|
You can not serialize a dictionary, if this is your dictionary, use KeyedCollection
|
|
|
|
|
In our application , we are used datagridview drag and drop itself , i was did properly , But i want visualization of the drag . Now visual only a default cursor point only .. How can i do visual of these drag and drop. I am used C# Windows application
Thanks....
|
|
|
|
|
Use the dragenter event to set the effect.
e.Effect = DragDropEffects.Move;
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi everyone!
I have an app: draw a resizeable and draggable rectangle on form.
Now i want to modify it to draw a resizeable and draggable rectangle on picturebox not on Form to select area and crop image.
I tried a few ways but i can't. I'm newbie in C#. Please help me! Thank you so much!
Here's my code:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace DragResizeRectangle
{
public partial class MainForm : Form
{
private RectangleF DragRect=new RectangleF(20, 20, 100, 80);
private System.Drawing.RectangleF[] Adornments = new RectangleF[0];
private bool MouseInRect = false;
private bool RectDragging = false;
private bool RectResizing = false;
private int ActiveAdornment = -1;
private Point MousePos;
private SolidBrush BackBrush;
private System.Drawing.Pen[] LinePen = new Pen[0];
public MainForm()
{
InitializeComponent();
}
void MainFormLoad(object sender, EventArgs e)
{
Adornments=new RectangleF[8];
LinePen=new Pen[2];
BackBrush = new SolidBrush(BackColor);
LinePen[0] = new Pen(ForeColor);
LinePen[1] = new Pen(ForeColor);
LinePen[1].DashPattern = new float[] { 5, 3 };
CalcAdornments();
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true);
}
private void CalcAdornments()
{
Adornments[0] = new RectangleF(DragRect.X - 4, DragRect.Y - 4, 8, 8);
Adornments[1] = new RectangleF(DragRect.X + DragRect.Width / 2 - 4, DragRect.Y - 4, 8, 8);
Adornments[2] = new RectangleF(DragRect.X + DragRect.Width - 4, DragRect.Y - 4, 8, 8);
Adornments[3] = new RectangleF(DragRect.X + DragRect.Width - 4, DragRect.Y + DragRect.Height / 2 - 4, 8, 8);
Adornments[4] = new RectangleF(DragRect.X + DragRect.Width - 4, DragRect.Y + DragRect.Height - 4, 8, 8);
Adornments[5] = new RectangleF(DragRect.X + DragRect.Width / 2 - 4, DragRect.Y + DragRect.Height - 4, 8, 8);
Adornments[6] = new RectangleF(DragRect.X - 4, DragRect.Y + DragRect.Height - 4, 8, 8);
Adornments[7] = new RectangleF(DragRect.X - 4, DragRect.Y + DragRect.Height / 2 - 4, 8, 8);
}
private void SetAdornmentCursor()
{
if (ActiveAdornment != -1) {
switch (ActiveAdornment) {
case 0:
Cursor = Cursors.SizeNWSE;
break;
case 1:
Cursor = Cursors.SizeNS;
break;
case 2:
Cursor = Cursors.SizeNESW;
break;
case 3:
Cursor = Cursors.SizeWE;
break;
case 4:
Cursor = Cursors.SizeNWSE;
break;
case 5:
Cursor = Cursors.SizeNS;
break;
case 6:
Cursor = Cursors.SizeNESW;
break;
case 7:
Cursor = Cursors.SizeWE;
break;
}
}
else {
Cursor = Cursors.Default;
}
}
void MainFormMouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left) {
if (MouseInRect & ActiveAdornment == -1) {
RectDragging = true;
MousePos = new Point(e.X, e.Y);
MousePos = PointToScreen(MousePos);
}
else if (ActiveAdornment != -1) {
RectResizing = true;
MousePos = new Point(e.X, e.Y);
MousePos = PointToScreen(MousePos);
}
}
}
void MainFormMouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left) {
Point CurrMouse = new Point(e.X, e.Y);
CurrMouse.X = Math.Max(0, Math.Min(CurrMouse.X, ClientSize.Width));
CurrMouse.Y = Math.Max(0, Math.Min(CurrMouse.Y, ClientSize.Height));
CurrMouse = PointToScreen(CurrMouse);
if (RectDragging) {
if (Math.Abs(CurrMouse.X - MousePos.X) > 2 | Math.Abs(CurrMouse.Y - MousePos.Y) > 2) {
DragRect.Offset(CurrMouse.X - MousePos.X, CurrMouse.Y - MousePos.Y);
DragRect.X = Math.Max(0, Math.Min(DragRect.X, ClientSize.Width - DragRect.Width));
DragRect.Y = Math.Max(0, Math.Min(DragRect.Y, ClientSize.Height - DragRect.Height));
MousePos = new Point(e.X, e.Y);
MousePos.X = Math.Max(0, Math.Min(MousePos.X, ClientSize.Width));
MousePos.Y = Math.Max(0, Math.Min(MousePos.Y, ClientSize.Height));
MousePos = PointToScreen(MousePos);
CalcAdornments();
Invalidate();
}
}
else if (RectResizing) {
if (ActiveAdornment != -1) {
if (Math.Abs(CurrMouse.X - MousePos.X) > 2 | Math.Abs(CurrMouse.Y - MousePos.Y) > 2) {
switch (ActiveAdornment) {
case 0:
DragRect.Height -= CurrMouse.Y - MousePos.Y;
if (!(DragRect.Height < 20)) {
DragRect.Y -= -CurrMouse.Y + MousePos.Y;
}
else {
DragRect.Height = 20;
}
DragRect.Width -= CurrMouse.X - MousePos.X;
if (!(DragRect.Width < 20)) {
DragRect.X -= -CurrMouse.X + MousePos.X;
}
else {
DragRect.Width = 20;
}
break;
case 1:
DragRect.Height -= CurrMouse.Y - MousePos.Y;
if (!(DragRect.Height < 20)) {
DragRect.Y -= -CurrMouse.Y + MousePos.Y;
}
else {
DragRect.Height = 20;
}
break;
case 2:
DragRect.Height -= CurrMouse.Y - MousePos.Y;
if (!(DragRect.Height < 20)) {
DragRect.Y -= -CurrMouse.Y + MousePos.Y;
}
else {
DragRect.Height = 20;
}
DragRect.Width += CurrMouse.X - MousePos.X;
DragRect.Width = Math.Max(20, DragRect.Width);
break;
case 3:
DragRect.Width += CurrMouse.X - MousePos.X;
DragRect.Width = Math.Max(20, DragRect.Width);
break;
case 4:
DragRect.Width += CurrMouse.X - MousePos.X;
DragRect.Width = Math.Max(20, DragRect.Width);
DragRect.Height += CurrMouse.Y - MousePos.Y;
DragRect.Height = Math.Max(20, DragRect.Height);
break;
case 5:
DragRect.Height += CurrMouse.Y - MousePos.Y;
DragRect.Height = Math.Max(20, DragRect.Height);
break;
case 6:
DragRect.Height += CurrMouse.Y - MousePos.Y;
DragRect.Height = Math.Max(20, DragRect.Height);
DragRect.Width -= CurrMouse.X - MousePos.X;
if (!(DragRect.Width < 20)) {
DragRect.X -= -CurrMouse.X + MousePos.X;
}
else {
DragRect.Width = 20;
}
break;
case 7:
DragRect.Width -= CurrMouse.X - MousePos.X;
if (!(DragRect.Width < 20)) {
DragRect.X -= -CurrMouse.X + MousePos.X;
}
else {
DragRect.Width = 20;
}
break;
}
MousePos = new Point(e.X, e.Y);
MousePos.X = Math.Max(0, Math.Min(MousePos.X, ClientSize.Width));
MousePos.Y = Math.Max(0, Math.Min(MousePos.Y, ClientSize.Height));
MousePos = PointToScreen(MousePos);
CalcAdornments();
Invalidate();
}
}
}
}
else {
MouseInRect = false;
ActiveAdornment = -1;
RectangleF tmprect = default(RectangleF);
int i = 0;
foreach (RectangleF tmprect_loopVariable in Adornments) {
tmprect = tmprect_loopVariable;
if (tmprect.Contains(e.X, e.Y)) {
MouseInRect = true;
ActiveAdornment = i;
SetAdornmentCursor();
Invalidate();
return;
}
i += 1;
}
if (DragRect.Contains(e.X, e.Y)) {
MouseInRect = true;
Cursor = Cursors.SizeAll;
Invalidate();
return;
}
Cursor = Cursors.Default;
Invalidate();
}
}
void MainFormMouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left) {
RectDragging = false;
RectResizing = false;
Invalidate();
}
}
void MainFormPaint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.FillRectangle(BackBrush, g.ClipBounds);
if (!MouseInRect) {
g.DrawRectangle(LinePen[0], DragRect.X, DragRect.Y, DragRect.Width, DragRect.Height);
}
else {
g.DrawRectangle(LinePen[1], DragRect.X, DragRect.Y, DragRect.Width, DragRect.Height);
g.FillRectangles(Brushes.White, Adornments);
g.DrawRectangles(Pens.Black, Adornments);
}
}
}
}
|
|
|
|
|
Hi,
your code seems pretty clean, although probably too wieldy and not correct.
Unfortunately your text isn't clear, "I tried a few ways but i can't" doesn't even start to describe what is going on.
Here are some thoughts:
1. the code shown describes your Form, so calling Invalidate() will cause the entire Form to be repainted; when you draw on a Control (e.g. a PictureBox), you should invalidate that Control, and make sure it has a paint handler to paint its stuff itself.
What may be happening right now is one of these:
- you Invalidate the Form, it repaints with a rectangle on top of your PB, then the PB itself repaints;
- you Invalidate the Form, it repaints with the exception of the areas taken by its controls, then it does not repaint the controls, as you did not explicitly ask for that to happen (see Invalidate(boolean)).
2.
A PictureBox is a tricky (I would add "and stupid") Control; it knows how to resize the image it holds (SizeMode), however such resizing will not apply to what you draw on top of the PB. For applications like yours I tend to use a Panel, and paint the image myself, in the same paint handler that draws the rectangle, and with the same transformation settings.
3.
You should use mouse handlers that belong to the Control of interest, that would yield coordinates relative to that Control; IMO there probably is no need to call PointToScreen and the like.
|
|
|
|
|
Hey all,
I came across one unusual behavior of Directory.Exists() method when I was testing user path input, I was trying with different inputs just to test the existence of the directory on my local drive. For negative test cases I provided the existing directory path and put two ".." at the end of directory path
e.g.
lets say I have "C:\CurrentDir" on my local drive
when I check the existence of directory using
bool isDirExist = Directory.Exists(@"C:\CurrentDir..");//".." are appended
surprisingly isDirExist is true
when I try to access file contained in this directory it throws error......
it does not throw exception if I append only one "." [for @"C:\CurrentDir." +AnyFileName]
Is this is bug in Directory.Exists method or anything else is happening behind the screen at OS level??
|
|
|
|
|