|
That's about what I'd do, although you should use the XmlNode methods for creating elements, creating their attributes and assign them values, and assign the values for the elements rather than using string.Format . It works, but there is no validation and it won't take into account namespaces should you ever use them.
You could also create an instance of an XmlTextWriter and use it's methods like WriteStartDocument , WriteStartElement , ... WriteEndElement , and WriteEndDocument . These methods are fully namespace-aware. It basically amounts to writing-out the XML document itself instead of creating one in memory and then writing it.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
HI,
My program has to trigger a dumb application that won't take paths with spaces.
Do you know if there is a built in function in C# that translates long file paths to short file paths.
Thank you,
Elena
|
|
|
|
|
There is nothing in the .NET base class library that does this (at least nothing public that I can remember / find), but - if your app runs on Windows 2000 or higher (any NT-based system) - you can P/Invoke the function PathGetShortPath :
[DllImport("shell32.dll", CharSet=CharSet.Unicode)]
public static extern void PathGetShortPath(string path); You pass the long path into the method and after it returns path contains the short path.
If you need something that works on all operating systems that .NET runs on, you'll have to enumerate each directory and the filename and change it to the 8.3 filename format. It's been a long time since I've worked with these, so you might want to check the PSDK to see if it documents how similarily named files or directories are resolved using the "~N" notation (like "MICROS~1", "MICROS~2", etc.).
You should also trying googling for the solution. I'm sure someone else has had to deal with this before.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Does not work on NT. It's only for 2000 and higher.
This API function call works on both OSes : ["kernel32.dll"] GetShortPathName(string szLongPath, string szShortPath, long dwLength).
RSS feed
|
|
|
|
|
How do you get the XP style using C#?
Larry J. Siddens
|
|
|
|
|
It is not built in unfortunately. However, you have come to the right place. Search CodeProject for XP Style[^] or click the previous link.
--Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)
Enumerators in .NET: See how to customise foreach loops with C#
|
|
|
|
|
I wrote an article here: http://www.codeproject.com/csharp/dotnetvisualstyles.asp[^]. If you target .NET 1.1 or higher, you can also call Application.EnableVisualStyles BEFORE you call Application.Run in your entry point (Main ). This only works on .NET 1.1 and higher, though, and achieves the same functionality as what I document in my article (which works for .NET 1.0 and higher).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath,
It was easy to use the Application.EnableVisualSytles() and make sure the controls FlatStyle was "System". Also, It worked in the C++ environment too!
Cool!
Larry J. Siddens
|
|
|
|
|
Note that C++.NET (Managed C++, or MC++) compiles to the same thing as C#, VB.NET, or any other languages targeting the CLR, so long as your MC++ is written using purely managed code (no mixed mode). This is important to understand: all managed languages compile to (roughly) the same thing: IL. They also have access to the base class library, as well as other assemblies no matter source language they were written in - they all contain IL code.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi Larry
I think I´ve got something for you
I can send you as attached zip file
email me
Huseyin
|
|
|
|
|
I am building an ASP.NET Web site with C#. The design is very much like a portal, where I can load/unload different controls withing the default page. In one of the controls, a user clicks a button to add an item to a "shopping cart", in another control. The first call to my "Add to Cart" function does nothing, however, subsequent clicks on the button work fine.
Any advice on this would be greatly appreciated.
Thanks,
Ben
|
|
|
|
|
It sounds like you're not loading controls in the right event handlers. There is a specific order to how things are handled (like the Page.Load event fires before a post-back event like a ServerClick or Button.Click event). If you look at some of the events in the SDK documentation for WebControl derivatives, there is a link that describes the order in which events are fired.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thank you for your response, however I can not seem to find what you suggested in the documentation. Could you be more specific on where I can find this in the SDK documentation?
Thanks a million.
Ben
|
|
|
|
|
Control Execution Lifecycle[^]
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi,
I want to ask a question about Regular expressions.
I want to validate the regular expression pattern if it is written correctly or not? I do not want to test a string against to a regular expression pattern but the regular expression pattern itself.
Is there a way?
Kind Regards
|
|
|
|
|
Just create a new instance of the RegEx . If the regex is invalid, an exception is thrown (this is documented in the class constructor information):
try
{
Regex re = new Regex("/mypattern/");
Console.WriteLine("The regular expression is valid.");
}
catch
{
Console.WriteLine("The regular expression is invalid!");
} If you move the re declaration outside, you can use it if it's valid after the catch (but then the catch should return or something to keep from trying to use the invalid Regex object).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks for your help Heath.
|
|
|
|
|
Hi,
I want to write a program that send a notififcation when files or folders in a path has been changed. So I've used FindFirstChangeNotification and WaitForMultipleObjects (same as a sample in MSDN document).
As I read the document when I use INFINITE for time-out of wait function, it will not be timed out. But in my sample after about one minute, wait function will be timed out.
Do you know what's the problem?
Mehdi
|
|
|
|
|
You should be using the FileSystemWatcher component instead. It already wraps all the native functionality up in an easy-to-use component. You can configure the FileSystemWatcher to watch for new, changed, or deleted files and it will fire events when what you want to watch occurs (like changed files or directories) with information about what was changed (one tip: the Changed event is fired three times for each change regardless of file size - after lots of research into event the native methods that the FileSystemWatcher wraps, I still can't figure out why - just make sure your code accomodates that).
As far as your problem goes, are you actually doing this using C#? INFINITE is actually a pre-proc definition for 0xffffffff (you could declare this as a const in C#) and if you're passing this as a string, the function will most likely use the default timeout.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi guys,
I need to give permission to an specific folder to a user using C#. Does anyone ever done that ? Is there any class capable of changing files and folders permissions in .NET ?
thanks in advance
Mauricio Ritter - Brazil
Sonorking now: 100.13560 MRitter
English is not my native language so, if you find any spelling erros in my posts, please let me know.
|
|
|
|
|
No, there are no classes in the .NET base class library that can do this, but there are ways you can P/Invoke the necessary functions. Search the comments for this forum, as I know we've talked about it before. I also remember seeing an article or two here on CP about the topic as well.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
When initially laying out the project, or a portion of the project, is it better to start with the interfaces and save the implementation code until later or just write the classes and then write the code that uses them?
Stated another way, Top down or Bottom up?
Thanks,
Ken Galer
Electrical Engineer
Preferred Utilities Corp.
Danbury, CT 06810
|
|
|
|
|
First, create a good design and then go either way. When it comes to UI logic, though (like handling click events and what-not), it's far easier to design the UI first. I personally like creating all my "utility" classes first, though. But jumping into either the front- or back-end without a good design is like diving into a pool without first checking the depth.
Also, when working with data-driven applications, it's better to develop at least the majority of your database elements (tables, views, stored procs, etc.) first. Creating business objects around these is also helpful, but not always necessary.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
i agree with u Heath Stewart
and i want to say that the analysing phase in so important and evry day in analysing save 5 days in implementaion time, and u can not start the first step in implementaion unless u finished the last step in analysing and design and u r already know what u r going to do till the end
|
|
|
|
|
I understand what both of are saying and agree. I think that I mis-stated the question.
Under the covers of the GUI, when designing whatever custom classes you require and their interfaces, do you normaly design the class:interfaces first and then the classes themselves after you are sure that you can use the classes the why you like?
I'm a C programmer trying to explicitly cast myself as a C# programmer so this is coming from a newbi.
Having just finished the chapter and FINALLY understanding the concept of interfaces ( i hope ) it seems to me that interfaces can act as sort of a prototype for the class.
Do you gyz, as experienced programmers in C#, find this to be useful or does it turn out to be not an issue?
Thanks
Ken Galer
Electrical Engineer
Preferred Utilities Corp.
Danbury, CT 06810
|
|
|
|