|
Hi,
I read from this tutorial at codeproject
Question A:
http://www.codeproject.com/csharp/GsXPathTutorial.asp
regarding xpath.. but i try to apply in my situation, and can't get it work...
just say this is my xml file:
Device.xml
=========
<?xml version="1.0" encoding="utf-8"?>
<DeviceList xmlns="http://tempuri.org/Device.xsd">
<!-- Device 1 -->
<Device id="1">
<Connection>
<Type>Titan123</Type>
<Open />
<ConfigCard>
<Name>Titan Suprema</Name>
<Length>13</Length>
</ConfigCard>
</Connection>
</Device>
<Device id="2">
<Connection>
<Type>BBB Hardware</Type>
<Open />
<ConfigCard>
<Name>BBB DH</Name>
<Length>6</Length>
</ConfigCard>
</Connection>
</Device>
</DeviceList>
In my C# code,
string devicePath = Application.StartupPath + @"\device.xml";
// open XmlTextReader
...
int nMaxId = 0;
// get maximum devices within XML script
while(xmlDevice.Read())
{
if (xmlDevice.IsStartElement() && xmlDevice.Name == "Device")
{
int nId = Int32.Parse(xmlDevice.GetAttribute("id"));
if (nMaxId < nId)
nMaxId = nId;
}
}
}
// Execute XPath here
XPathDocument xdoc = new XPathDocument(devicePath);
XPathNavigator nav = xdoc.CreateNavigator();
// loop into 2 possible devices and extract particular information
for (int i = 1; i < nMaxId + 1; i++)
{
XPathNodeIterator nodeItor = nav.Select(
"DeviceList/Device[@id='" + i + "']/Connection");
nodeItor.MoveNext();
TraverseChildren(nodeItor);
}
...
// from the article
private void TraverseChildren(XPathNodeIterator nodeItor)
{
XPathNodeIterator igor = nodeItor.Clone();
igor.Current.MoveToFirstChild();
bool more = false;
do
{
PrintNode(igor.Current);
more = igor.Current.MoveToNext();
}while(more);
}
private void PrintNode(XPathNavigator nav)
{
MessageBox.Show("Value: " + nav.Value +
" Type : " + nav.NodeType.ToString());
}
From this solution:
i get this instead:
MessageBox1 - Value: Titan123 Titan Suprema 13BBB Hardware BBB DH 6
MessageBox2 - Value: Titan123 Titan Suprema 13BBB Hardware BBB DH 6
(repeat the same message - why?)
Any help please?
I want to get the Output of this:
MessageBox1 - Value: Titan123 Titan Suprema 13
MessageBox2 - Value: BBB Hardware BBB H 6
Question B:
By the way how can i get the value of individual Type example,
showing the output here:
Type - Titan123
Name - Titan Suprema
Length - 13
i always only manage to get the type which is "Name" and the whole message "Titan123 Titan Suprema 13" instead separate data.
Any help please? Thanks.
Regards,
Chua Wen Ching
Visit us at http://www.necoders.com
|
|
|
|
|
If you have a question about an article here on this site, then use the message board at the bottom of the article. That's what the article-specific message boards are for.
http://www.codeproject.com/csharp/GsXPathTutorial.asp[^]
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello
I want to make an application which will list down all the sites and directories present in IIS in C# application..i found code snippets for creation of site and Virtual Directories but didn`t find any example for viewing the hosted sites
is there anyway to achieve this goal?
Please Help me
-adnan
|
|
|
|
|
The APIs that those samples used are the very APIs (most likely) for enumerating virtual sites and directories. It's important to understand the scope and goal of the examples, not to simply copy and paste for the same functionality.
Since I don't know what examples you're talking about and since there's so many ways of creating, enumerating, and deleting virtual hosts and directories, I recommend using System.DirectoryServices to enumerate the iis:// namespace provider. See http://www.netomatix.com/EnumWebDirs.aspx[^] for an example.
This is the preferred way of accessing IIS information and is supported by many automation clients, including Windows Script (VBScript; JScript), Visual Basic 6 / VBA, and more. .NET supports this through the System.DirectoryServices namespace that I mentioned before.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks for reply,can you explain me about this syntax?
IIS://" + this.DomainName + "/W3SVC
i have oftened seem syntax like
IIS://" + this.DomainName + "/W3SVC/1
What`s the difference?
-adnan
|
|
|
|
|
If you search for "iis://" on http://msdn.microsoft.com/library[^] you can learn quite a bit about it.
this.DomainName is just what it sounds like - the domain name. Replace this with whatever computer you want to connect that is running IIS. The IIS Programmatic Administration Reference[^] - specifically for the IIS ADSI Provider[^] - descrbes that what comes after the computer name is the service to which you want to connect. "W3SVC" is the world-wide web (w3) service (svc). The number after that is the virtual host number (this is not necessarily serialized).
The first line enumerates all virtual hosts, while the second enumerates the first virtual host (or rather, the virtual host who's identifier is "1").
Read the links above for more information.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks i tried the code and it worked..however i want to know that is it possible to view all VirtualFolders and site at once?
i created a site in my IIS as "abc.com" and then i provided
path as IIS://abc.com/W3SVC/1/Root
but it gave RPC error
how can I do this?
Thanks
-adnan
|
|
|
|
|
If you read the documentation that I linked it explains how to enumerate all virtual sites. As I also mentioned, the site index (represented by the "1" in your URL above) is not a serial number and is seemingly random. This is why you must enumerate the sites first, then their services, then their applications and their directories, and so on.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
thanks for keep sending me replies..i was actually giving machine name as "localhost" though my Machine name is something else
one thing i didnt understand that what`s the different between "IISWebDirectory" and "IISVirualDirectory" i can understand Virtual directory which normaly is created under "localhost" website but what`s webdirectory?
-adnan
|
|
|
|
|
If you look at the documentation I link it should hopefully be clear. A virtual directory is a directory that doens't exist below the web root directory, but that was mapped into the web site. A web directory is a physical directory either under the web root or under a virtual directory (so a directory of the mapped directory, or one of the descendent directories).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks a lot
with the help of your kind guidance i have got some output..i can see all sites and their associated VDirs one by one..
-When I used the Syntax IIS://Machine/W3SVC it displayed the following O/p and ifound that some hiddenn "folders" like Info or Filters which normally i hadn`t seen in IIS, 1 ,2 and 3 were the sitesi created on my server..
C:\>IISDIRECTORI
Info=>IIsWebInfo
1=>IIsWebServer
Filters=>IIsFilters
2=>IIsWebServer
3=>IIsWebServer
ok now the issue is that even i close the server,i still get the result ,it don`t show Server close error or Exception message..how can I trace this?
Once again i am very much thankful of your kind help and I am sure i would achieve my goal..thanks
-adnan
|
|
|
|
|
IS it not possible to get the Site Description/site Name rather than these Numeric IDs?
-adnan
|
|
|
|
|
Hi all,
I want to retrieve objects from database by SQL. But if the matched
objects number size is huge (e.g. 1000 records), and I want to just get
40 result records for each fetch. How can I write the SQL to achieve this ?
(I don't want to write another SQL to project the first SQL results to 40 record)
Thanks
|
|
|
|
|
|
hi
i have this in the form constructor:
GraphicsPath p = new GraphicsPath();
Point[] points = { new Point(0, 0), new Point(100, 0),
new Point(150, 50), new Point(250, 50),
new Point(250, 350), new Point(0, 350) };
p.AddPolygon(points);
this.Region = new Region(p);
which creates a poligonal form.
i want to have the upper part colored, and im using the same coordinates, like:
Graphics g = e.Graphics;
Point[] points = { new Point(0, 0), new Point(100, 0),
new Point(150, 50), new Point(0, 50)};
Rectangle r = new Rectangle(points);
g.FillRectangle(new SolidBrush(Color.Aqua), r);
but the colored part doesnt match the part of the window i expect! do i have to make coordinates shift or something? i tried rectangletoscreen etc but nothing worked ...
|
|
|
|
|
Control.RectangleToScreen converts client coordinates to screen coordinates, which is not what you want.
Judging by the coordinates, it seems that you're assuming that by setting the clipping region the root coordinate is changed. It's not. A window is always defined by a rectangular area, but by setting a clipping region (or using layered Windows on Windows 2000 and above, which is what the Form.Opacity property uses) you tell the window manager not to draw in that particular region. The root coordinate is unchanged. If you were to clip a rectangle {0, 0, 10, 10} then to start a line at the corner of the clipped area you'd need to start it at {10, 10} (actually just a little past, which is why using the "F" structures like PointF and SizeF is helpful such that rounding to whole numbers of pixels usually takes into account the discrepency).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
but my region starts from (0, 0) and i want to fill a region starting from (0, 0) too - so it does start from there, but when i give a bottom right corner of (150, 50) it does not match with the (150, 50) point i used for the region before!
and this is my problem.
i understand that the root coordinates are unchaged - thats what i count on - why does the fill go with wrong coords ?
|
|
|
|
|
You'll need to be a little more specific. If you can, please posts a couple of screenshots of what you have and (if you can muster it) what you'd like to see, as well as the contents of your OnPaint method and any methods called less frequently (preferrably, for performance) to calculate the region.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
how about some ASCII art ?
the initial window:
xxxxx
xxxxx
xxxxx
xxxxx
the nonrectangular window:
yyy
xxxxx
xxxxx
xxxxx
i want the yyy part colored.
and thats where the coords fail me - i get something like
yyy
yyyyx
xxxxx
xxxxx
all the code i use is in my first post
|
|
|
|
|
The ASCII art's not bad, but next time enclose each segment in <PRE></PRE> tags so that it's truly ASCII art (fixed-width).
Out of curiosity, are you drawing tabs for a custom tab control? If so, you should owner-draw tabs or at least not define the tabs themselves as controls. You can do it that way, but that's pretty heavy-weight compared to a single control (like the TabControl in the BCL) managing what's visible using components (like the TabPage in the BCL).
One problem I see is that with the second block of code where you add a colored rectangle, you're not actually adding a rectangle. You're adding another polygon. The following extents do not a rectangle make (a little Yoda speak for you):
{0,0} {100,0}
{0,50} {150,50} Try making it an actual rectangle (changing 150 to 100, I'd assume) or drawing a polygon using the Graphics object passed to you from the PaintEventArgs in your OnPaint override and see if that works.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
hi, heath, thanx for bearing with me
no this is not a custom tab control, but a non rectangular window. the intent is for the upper poligonal(nonrectangular) part to be used as a handle to mousedrag the window by.
the first part of the code is in the contructor, and the second goes inside the OnPaint override.
im copying the code again -
in the constructor:
GraphicsPath p = new GraphicsPath();
Point[] points = { new Point(0, 0), new Point(100, 0),
new Point(150, 50), new Point(250, 50),
new Point(250, 350), new Point(0, 350) };
p.AddPolygon(points);
this.Region = new Region(p);
in the Paint override:
GraphicsPath p = new GraphicsPath();
Point[] points = { new Point(0, 0), new Point(100, 0),
new Point(150, 50), new Point(0, 50)};
p.AddPolygon(points);
g.FillPath(new SolidBrush(Color.Aqua), p);
g.DrawPath(Pens.Red, p);
if you paste this directly into a windows form application code you will see what i mean (i would have posted the entire solution if i knew how to do it here
|
|
|
|
|
You shouldn't be doing redundant calculations in your OnPaint override; you waste CPU cycles. If the GraphicsPath doesn't change, then don't keep recalculating it. OnPaint (or rather, the WM_PAINT window message) is called many, many times by the OS.
To post code, simply copy and paste the code in between <PRE></PRE> tags and escape any characters like < with <, > with >, and & with &
You also don't need VS.NET. I added csc.exe's directory (the Framework version directory) to my PATH environment variable (as well as the SDK's Bin directory) and do almost everything you'd see from me on this site using a vanilla text editor called VIM[^] and the command-line compiler.
With a VIM script, I can post this easily to this site:
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
class Test : Form
{
static void Main()
{
Application.Run(new Test());
}
GraphicsPath grabHandle;
Brush pathBrush = new SolidBrush(Color.Aqua);
Pen pathPen = new Pen(Color.Red);
Test()
{
GraphicsPath p = new GraphicsPath();
Point[] points = new Point[] {
new Point(0,0),
new Point(100,0),
new Point(150,50),
new Point(250,50),
new Point(250,350),
new Point(0,350)};
p.AddPolygon(points);
this.Region = new Region(p);
grabHandle = new GraphicsPath();
points = new Point[] {
new Point(0,0),
new Point(100,0),
new Point(150,50),
new Point(0,50)};
grabHandle.AddPolygon(points);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
g.FillPath(pathBrush, grabHandle);
g.DrawPath(pathPen, grabHandle);
}
} So far as I know, it appears to work just fine.
If you need to post a picture of what you expect, drawing something up (may I suggest the free Paint.NET[^] application from Washington University and Microsoft) and post it online. Surely you have a site somewhere where you can post a simple image. If not, you can email it to me but only as a last resort (and never continue a thread from this site personally - I get very irritated since this site contains wonderful forums). My email address you'll find in the automatic email notification message that gets sent to you when I reply to your post.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
dont worry i would bother you for something as silly as this
i've compiled your code and i got what i have achieved already:
http://viewmoresoft.com/rez1.jpg
but my goal is
http://viewmoresoft.com/rez2.jpg
i've setup the form so it is without the title bar etc
when i do a fill of the region it fills the entire visible area, but when i want to get my poligon filled it does it not the way i want.
can you see what i am trying to achieve now ?
|
|
|
|
|
In the future, please format your links to actually be links. The format toolbar below the message window is handy, and you can always use basic HTML elements when posting.
Now that I have some idea of what you want, it's quite a easy. You didn't notice that width of the angled portion was exactly the same as the width of the Windows title bar? The window frame is the non-client portion, so when you were setting your clipping area amounts where adjusted. If you set Form.FormBorderStyle to FormBorderStyle.None you'll get what you want:
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
class Test : Form
{
static void Main()
{
Application.Run(new Test());
}
GraphicsPath grabHandle;
Brush pathBrush = new SolidBrush(Color.Aqua);
Pen pathPen = new Pen(Color.Red);
Test()
{
FormBorderStyle = FormBorderStyle.None;
GraphicsPath p = new GraphicsPath();
Point[] points = new Point[] {
new Point(0,0),
new Point(100,0),
new Point(150,50),
new Point(250,50),
new Point(250,350),
new Point(0,350)};
p.AddPolygon(points);
this.Region = new Region(p);
grabHandle = new GraphicsPath();
points = new Point[] {
new Point(0,0),
new Point(100,0),
new Point(150,50),
new Point(0,50)};
grabHandle.AddPolygon(points);
Label lbl = new Label();
Controls.Add(lbl);
lbl.Location = new Point(8,58);
lbl.Size = new Size(200, lbl.Height);
lbl.Text = "Click anywhere to close";
lbl.Click += new EventHandler(Clicked);
}
void Clicked(object sender, EventArgs e)
{
Close();
}
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
Close();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
g.FillPath(pathBrush, grabHandle);
g.DrawPath(pathPen, grabHandle);
}
} You'll need to adjust your border line, though. Because of a behavior similar to - if not related - to culling some lines won't be visible. You could thicken your border a little and contract it a pixel or two (depending on the new thickness), or you'll need to adjust it manually based on the thickness.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
this is still not it
this is what your code and mine so far achieve. sorry, maybe i have mislead you, but in my code i do use FormBorderStyle.None, havent pointed it out, my mistake.
however what i want to achieve is this (the part in purple). do you see the difference?
i am very thankfull for your time and help.
|
|
|
|
|