|
I'm not sure to understand the problem here, and I may not be alone...
You have the nodelist. You want to crop it out to get 3 out of the 30? Is that it?
What's your criteria for selection? It seems to me you can sort in many ways, and then pick the first 3. Select nodes out of the list with XPath, or an XSL transform, since RSS is all XML.
Maybe I'm missing your question here... but in any case, there is nothing logical that's impossible to code!
|
|
|
|
|
>> You want to crop it out to get 3 out of the 30? Is that it?
Thats exactly it.
Basically some pages will display 25 stories some 2 etc.
>> but in any case, there is nothing logical that's impossible to code!
Agreed ;o)
|
|
|
|
|
In case anybody else is looking for the solution to this:
xDoc.SelectNodes("rss/channel/item[position()<8]");
|
|
|
|
|
Will this[^] article help?
/ravi
|
|
|
|
|
Hi All,
I have a TreeView for which I have created images. Rather than using a single image per item, I've created an array. So rather than than a 16x16 BMP, I am using an array of 16x16 BMP's. The array includes standard and selected images. They are laid out as [standard, selected] pairs.
I add the image to the the tree view. However, when dispalyed, there are no images. I beieve this is because the control is not performing the derefernce into the array. How do I get the TreeView to properly use the array of images? TreeView uses and ImageList, and the array is a list (I think...).
Jeff
public static ImageList images = new ImageList();
...
images.Images.Add(new Bitmap("TreeViewImages.bmp"));
TreeView.ImageList = images;
...
TreeNode node = new TreeNode();
...
int ImageIndex = GetImageIndex(GetTagNumber());
node.ImageIndex = ImageIndex;
node.SelectedImageIndex = ImageIndex + 1;
private static int GetImageIndex(int number)
{
return ...;
}
|
|
|
|
|
Hi All,
Using a custom ICO (960x16) produces the same reults.
Jeff
|
|
|
|
|
Also does not work, since there is no correspong ImageCount:
images.Images.Add(new Bitmap("TreeViewImages.bmp"));
...
images.ImageSize = new System.Drawing.Size(16,16); And the following does not work (it throws an exception that size.width must be less than 256)
images.ImageSize = new System.Drawing.Size(960,16);
|
|
|
|
|
In case anyone is interested, here's a solution which I hacked together. This paradigm reeks of Java. I disliked it in college years ago, and I still have not acquired a taste for it...
The image files were embedded in the executable (select the Image -> Properties, Build Action = "Embedded Resource"). assemblyname and assembly are static so they only have to be calculated once, without the extra argument passing. If you're into software engineering, hack it further the Java way.
TreeView Tree = new TreeView();
TreeViewImageHelper helper = new TreeViewImageHelper();
...
Tree.ImageList = helper.CreateImageList();
public class TreeViewImageHelper
{
private static string assemblyname = null;
private static Assembly assembly = null;
public TreeViewImageHelper() { }
public ImageList CreateImageList()
{
ImageList list = new ImageList();
string[] filenames = {
"Certificate.bmp",
"CertificateSelected.bmp",
"Message.bmp",
"MessageSelected.bmp",
null
};
for (int i = 0; filenames[i] != null; i++)
{
Stream stream = GetEmbeddedFile(filenames[i]);
if (null != stream)
{
list.Images.Add(Bitmap.FromStream(stream));
}
}
return list;
}
public Stream GetEmbeddedFile( string filename )
{
if( null == assemblyname )
{ assemblyname = Assembly.GetExecutingAssembly().GetName().Name; }
if (null == assembly)
{ assembly = System.Reflection.Assembly.Load(assemblyname); }
Stream bitmapstream = null;
try
{
bitmapstream = assembly.GetManifestResourceStream(
assemblyname + ".Resources" + "." + filename
);
}
catch
{ return null; }
return bitmapstream;
}
public int GetImageIndex(int number)
{
}
}
|
|
|
|
|
Hi Jeff,
I have not used ImageLists yet, but here are three remarks:
- what is GetTagNumber()?
- why the detour, why not just have a global imageIndex that increments by 2?
- the MSDN example sets TreeView.ImageList after the list has been loaded.
Hope this helps.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Hi Luc,
Luc Pattyn wrote: - what is GetTagNumber()?
It is an enumeration. It returns 0, 1, 2, 3,... 30.
Luc Pattyn wrote: - why the detour, why not just have a global imageIndex that increments by 2?
A layer of abstraction. Previously, I was combining two list with the Add method. Depending on the enumeration, it went ti one list or the other.
Luc Pattyn wrote: - the MSDN example sets TreeView.ImageList after the list has been loaded.
Been there, done that.
In C++, this was typical - load the resource, then specify the index. I'm not sure where the disconnect is occuring with C#.
Jeff
|
|
|
|
|
Hi Jeff,
I've got your TreeViewImageHelper class up and running. Here are some comments:
- when the resource is not found, you catch an exception, ignore it, and return null
in GetEmbeddedFile(); the minimum you should add is some code to log the exception;
that way, you will probably see none of your resources get loaded.
} catch(Exception exc) {
log(exc.ToString());
return null;
}
where log(string s) could be as simple as Console.WriteLine(s);
- the most likely reason is you must add the images to the Visual Studio project,
set their property "Build Action" to "Embedded Resource", but also make sure they are
located where your code looks for them, in your case in a folder named "Resources"
(do an "Add Folder" in the Solution pane, and drag the image files in it), because that
is the consequence of assemblyname + ".Resources" + "." + filename
warning: the folder name is case-sensitive!
- you could drop the null in filenames, and replace the for by a foreach:
foreach(string filename in filenames) {...}
- IMO you can simplify the assembly/assemblyname stuff in GetEmbeddedFile() to:
if(null == assemblyname) {
assembly=Assembly.GetExecutingAssembly();
assemblyname = assembly.GetName().Name;
log("assemblyname ="+assemblyname);
}
Regards,
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Hi Luc,
Thanks for going over it. I appreciate the help.
Luc Pattyn wrote: foreach(string filename in filenames) {...}
I think that's my C++ coming out...
Jeff
|
|
|
|
|
Running on Vista x64, I have a FolderBrowser dumped on the form to allow the user to select... er... folders. If the user is foolish enough to select Network > Printers and hit ok, as soon as I try and access the FolderBrowser's SelectedPath property it throws a NotSupportedException.
2 Questions:
1) I haven't tested this on XP, but could anyone confirm if the same behaviour occurs.
2) Apart from a Try...Catch after the fact, is there a way to prevent this daft error from happening in the first place (shooting the user, sadly, is not an option )
Cheers,
Martin.
"On one of my cards it said I had to find temperatures lower than -8. The numbers I uncovered were -6 and -7 so I thought I had won, and so did the woman in the shop. But when she scanned the card the machine said I hadn't.
"I phoned Camelot and they fobbed me off with some story that -6 is higher - not lower - than -8 but I'm not having it."
-Tina Farrell, a 23 year old thicky from Levenshulme, Manchester.
|
|
|
|
|
Hi Martin,
I did a test on XP, I didn't see a Network Printers, but got an UnauthorizedAccessException
on C:\System Volume\Information.
And of course you should use a try-catch: there is input/output involved, it can always
fail (some one/some process could move/delete a file/folder before you could click OK,
a network drive could suddenly get disconnected, etc.)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Luc Pattyn wrote: And of course you should use a try-catch: there is input/output involved, it can always
fail (some one/some process could move/delete a file/folder before you could click OK,
a network drive could suddenly get disconnected, etc.)
Good tippage - thanks Luc (although one can't help but wonder what other nasties this control might be hiding!)
"On one of my cards it said I had to find temperatures lower than -8. The numbers I uncovered were -6 and -7 so I thought I had won, and so did the woman in the shop. But when she scanned the card the machine said I hadn't.
"I phoned Camelot and they fobbed me off with some story that -6 is higher - not lower - than -8 but I'm not having it."
-Tina Farrell, a 23 year old thicky from Levenshulme, Manchester.
|
|
|
|
|
Dear ALL,
I am in process of developing a network management appliction primarly based on WMI, I have this query "How can I retrive list of open network connections" by a specfic machine (such as open ports n all on a machine).
By either some conventional approach or using WMI?
Thank you!
M. Nauman Yousuf
"Mess with the Best, Die like the rest"
|
|
|
|
|
Hello to all.
I am sorry in advanced if my problem is very basic and seem obvious to you.
My situation is as follows,
I want to open a log file in my application and write to it occasionally.
I want to write to it a regular text, not bytes, but a streamWriter doesn't have the option of opening
a file in a shared mode(so I can open another instance to read the file).
I need the two abilities together SO,
How do I open a file in shared mode(something the FileStream allows me),
and write to it strings as if to Console I/O(like StreamWriter enables me).
I thank in advanced for any help.
|
|
|
|
|
Create the FileStream object with desired access and pass it to streamwriter's constructor
|
|
|
|
|
Thanks man, this was very short and helpful.
where do I do the rating?
|
|
|
|
|
Just below the message there is 'Rate this message' at right corner. Thanks for voting
|
|
|
|
|
I thought you were going to vote for my previous reply.
|
|
|
|
|
Thanks man,
Still I am having a problem.
I can't open another instance of the same file for reading, I get an exception:
The process cannot access the file 'C:\Logs\log 2007-11-17_part1.log' because it is being used by another process.
the code I used to open the first file and the second file is as follows:
first:
try
{
_fileController = new FileStream(_fileName, FileMode.Create, FileAccess.Write, FileShare.Read);
_fid = new StreamWriter(_fileController);
}
second:
fsArr[index] = new FileStream(fileName, FileMode.Open, FileAccess.Read);
How come I receive the error????
|
|
|
|
|
-- corrected 17-NOV-2007
IMO you should explicitly set FileShare values for all parties.
Either allow Read (if there are no writers), or ReadWrite (if at least one party will be
writing, your case).
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
First of all, the code you use to create a FileStream object creates new file so the second instance of your application will try to create file which was created by first instance and not open for reading.
Secondly, according to MSDN FileShare.Read: "Allows subsequent opening of the file for reading. If this flag is not specified, any request to open the file for reading (by this process or another process) will fail until the file is closed. However, even if this flag is specified, additional permissions might still be needed to access the file."
Finally, here is a solution for your problem: Simultaneously Write to and Read from the same file[^]
|
|
|
|
|
Hi Giorgi,
First of all, the code you use to create a FileStream object creates new file so the second instance of your application will try to create file which was created by first instance and not open for reading.
my second instance is only creating a new fileStream that will open an existing file(the one created before) for reading.
at list that is what I understand of it. please feel free to correct me if I am wrong.
thanks.
|
|
|
|
|