|
Hello, and thanks for taking the time to read me...
I am starting with Visual C# to build a Windows application, although I have long experience with Web design in PHP, Javascript, XML/XSL...
I am trying to build a program that would use data from an XML Database file, locally, with online updates.
The program needs to be able to run offline, but check for updates on the XML file when online.
So I have several questions:
- First, I'd like to understand how program updates work: Is there a standard protocol in Visual C# that looks for application updates? Or do I need to program that?
If so, I assume it looks for update of the .EXE, or how would it handle external files?
- So then, I was thinking it may be easier to embed the 'local' XML into the program, and hide it from the user, but I don't see an easy way to use my XML directly. It seems like no matter what I do, I should 'load' the XML into a dataset, which to me sounds absurd since Visual C# is supposed to handle XML in native. After all XML is a structured object, so why can't I access it directly? (or if I can, please tell me how!!!)
The idea behind using XML is that most of my data is formatted text that I later need to output in the form of Word or PDF documents, so it seems obvious to store the data in XML and use XSL:FO transforms on the data to output in the format I want in the end.
I also find a little odd that Visual C# would only handle formatted text as RTF, and not HTML or XML with XSL, but RTF is easy enough to transform in XML, so I'll deal with that... unless someone knows of controls designed to handle HTML/XML editing easily (and that won't cost me a fortune!)
Any insight would be very welcome!
Thanks!
|
|
|
|
|
You may want to look at the ClickOnce API for updating your app. http://msdn2.microsoft.com/en-us/library/t71a733d(VS.80).aspx[^]
You can retrieve the XML and load it into an XmlDocument. Then you can access it using XPath expressions, or iterator over nodes, or however you need to.
only two letters away from being an asset
|
|
|
|
|
Thanks for the tip on ClickOnce.. .that seems ot be what I need to look into.
Now, I see I can load my files into an XmlDocument, and then do whatever with it. Is there a way to actually embed an XML file onto the program?
It seems like I can load a new 'Item' to my project... but then what how do I access it? Do I still have to 'link' or 'load' it as a xml.document?
I have to admit I am a little lost with all the different 'items'
|
|
|
|
|
|
Hello,
Simple problem but its causing me grief.
I want to consume an RSS feed and display a varying amount of stories on different web pages.
If I retrieve the xml document and then use xpath to drill down to the items I get a nodelist like so:
XmlNodeList nl = rssDoc.SelectNodes("rss/channel/item");
Now, what is the best way (if this list contains say 30 stories) to convert it to a node list of say 3 stories?
I appreciate this is probably either:
a. 2 lines of code
b. not possible.
Help please?
|
|
|
|
|
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
|
|
|
|
|