|
My application must resolve dns name of host. Iam tryning
string HostName = System.Net.Dns.GetHostByAddress( "207.219.70.31" ).HostName<br />
its error
"An unhandled exception of type 'System.Configuration.ConfigurationException' occurred in system.dll
Additional information: Configuration file E:\Baton\AnonMailer\bin\Debug\AnonMailer.exe.config does not have root <configuration> tag"
Im using Custom application configuration[^]
Thanks,
|
|
|
|
|
I want to make a class which automatically truncates text to a specified length. This is how I would like to use it while coding.
Text text = new Text(4);
text = "This text will be truncated to 4 characters.";
string truncated = text;
Truncated now should return a value of "This". Remember, this is a simplified example of what I want to do. I want to have a lot more properties and functionality than length.
Returning the value isn't a problem. I can write a conversion operator: public static implicit operator string(Text text).
But, after looking further into operator overloading I came to the conclusion that it is impossible to perform the truncation. I can never have access to the length, because operator overloading uses static functions.
I can think of several solutions to this problem but the code to use it is uncomfortable.
1. Using a new Text(...) each time. Too many properties and too much chance for errors. I really don't want to look up each time which values I need this time.
2. Since I was going to use Properties to access the Text class I could reapply all values in the set function. I could get the desired syntax but this leads to some really awful code. Plus, each time I would instantiate a new object I need to update the reference in two places.
3. Using a property in the text class: text.Data = "This ...". I guess this is the best solution although I really hate the syntax.
Can anybody come up with a good solution?
|
|
|
|
|
|
I'd completely agree with you if all that I wanted to do was just truncate a string.
Here's the thing that I want to accomplish: a DataSet is a great object to contain data, but it's a bit difficult to access. I would like to write a wrapper around it to access fields in a row straightforward and without casting. I want to have functions like NextRow and PreviousRow, ...
The fields (like Text) are going to read the data out of the DataSet. This is no problem at all. But when I want to place data in the Dataset I want to preprocess it before changing the dataset. Length was just one example. Another example could be making text uppercase for a key field or verifying that a number is between some values, or even more complex functions.
In C++ I could overload the assignment operator. I was just surprised that it wasn't possible in C#. I really do like the language and I'm determined to use it. I just have to find a decent workaround.
Basically, I'm trying to create an easily accessible and extendable framework to work with a lot of data. Over time there are going to be hundreds of tables. I'd rather do the extreme part early then later and since the project isn't even started I'm free to experiment and take my time without the pressure of a release date.
|
|
|
|
|
So why not just create a wrapper for the DataRow. In the past I have used code like this:
public class Person {
private DataRow theRow;
public Person(DataRow row) {
theRow = row;
}
public string Name {
get {
return (string)theRow["PNAME"]
}
set {
theRow["PNAME"] = value.Substring(0,40); // only stores 40 chars
}
}
public DateTime BirthDate {
get {
return Convert.ToDateTime(theRow["BDATE"])
}
set {
if (value > DateTime.Now) throw new Exception("Invalid date");
theRow["BDATE"]=value;
}
}
public override string ToString() {
return Name + " was born " + BirthDate.ToString("d");
}
}
Now you can write client code like this:
DataTable table = new DataTable("People");
// use ADO.NET/Xml to load table
foreach(DataRow row in table.Rows) {
Person p = new Person(row);
Console.WriteLine(p.ToString());
}
This is very similar to the code generated by XSD.exe. Though, I find writing the code yourself gives you a lot more control over the evolution of the class. You can add your own methods, throw exceptions when a property is set with an invalid value..etc..etc.
|
|
|
|
|
Thanks for the suggestion. I'll definitely consider it. The only thing that I don't really like is the fact that I have to program each field separately. You'll get total flexibility at a price.
|
|
|
|
|
How can I find out programmatically if there is a dial-up connection to the internet in C#? I've looked through the MSDN stuff but it's heavy goinga as I've done no internet coding before. All I need to be able to do is check for internet connections, and if there are any, then disconnect them.
Dave Kerr
focus_business@hotmail.com
www.focus.esmartweb.com
|
|
|
|
|
This might be a simple question to some but has caused me a few too many brain cells. I do not see any way possible to conditionally use an event. That is, in a standard class you can override the method and then if you choose, you can call the base class to execute that code. As a multicast event will call the handlers in order they where added, I can see no way to bail and revert to some default processing if certian conditions arise from within your handler.
Wondering if this has ever been an issue..
Rocky Moore
|
|
|
|
|
|
I'm making an IRC Bot for statictics and I need to launch it into the background(like eggdrop). This bot runs in linux with mono(Free .NET Implantation).
Does anybody has any clue about this?
Trully, if there evil in this world, It lies within the heard of mankind
Shock The Dark Mage
shock@romhack.net
Main Project: Aeru IRC - http://www.sf.net/projects/aeruirc
|
|
|
|
|
|
Thanks again leppie, but if you know how to program it in the program rather than using the &, let me know.
Trully, if there evil in this world, It lies within the heard of mankind
Shock The Dark Mage
shock@romhack.net
Main Project: Aeru IRC - http://www.sf.net/projects/aeruirc
|
|
|
|
|
In UNIX, in order to have the program put itself in the background, it needs to fork a child process. True system daemons are double-forked. The first fork puts the program in the background, the second fork isolates itself from the current process group (e.g., a user's session). However, Windows has never supported the concept of fork(), so it would be surprising to see it in .NET.
It appears that Mono is closely following the .NET SDK to make sure that Mono (.NET) programs are cross-platform, but in case there is a concept of fork() within Mono, go with that. For a 100% pure .NET cross-platform program, I'd suggest you take a peek at System.Diagnostics.Process.
|
|
|
|
|
I need to find a smaller string of characters inside a larger string, but have no idea how to go about it. I know there is the 'SubString' method, but that will not work in this case, as the sting i am looking for will be in different locations withing the large string, or it may not be in there it all.
I am just trying to test for it's existance(true/false).
Any help would be appreciated.
********************
* $TeVe McLeNiThAn
********************
|
|
|
|
|
See String.IndexOf method in help. This returns the integer index of the first character of a substring in another string, -1 if not foune, 0 if the substring requested is an empty string.
Some ideas are so stupid that only an intellectual could have thought of them - George Orwell
|
|
|
|
|
Hmmm the documentation for String isn't that difficult to follow!
Try String.IndexOf(String)
|
|
|
|
|
How can export specific record(s) in MS Access mdb file to text comma seperated file?
Jassim
|
|
|
|
|
I would look at pulling the stuff into a DataSet and then exporting it as XML instead of csv files. Why do you need it as a text file?
I don't know whether it's just the light but I swear the database server gives me dirty looks everytime I wander past.
-Chris Maunder
Microsoft has reinvented the wheel, this time they made it round.
-Peterchen on VS.NET
|
|
|
|
|
ok but can you tell me about the following :
1. can I have a sample code please?
2. Can I protect the XML file with password so that no body will be able to view the contents?
Many Thanks,
|
|
|
|
|
How can I update the MDI container statusBar text from the MDI child? can I have an example please...
Jassim
|
|
|
|
|
Has anyone delved into the deep dark secrets of Outlook connectors with C#?
All the references I have seen ("Inside MAPI" and MSDN) show C++ references. In particular, each connector type has a set of launch functions (the main one of which basically goes "create me a COM object and return it") and a set of COM enabled classes.
Now, I'm guessing here that I can fairly reasonably create the COM Classes using COM Interop. What is mystifying me is how do I deal with the launch functions within a C# DLL?
Any ideas?
-Adrian
|
|
|
|
|
Hi,
I've written a custom windows control, that displays an OpenGL scene, but I'm having troubles with it's properties. I can programmatically modify the properties fine, adding objects etc. I can also do this at design time, using the properties window. However, any changes I make at design time don't last, as soon as I run the program, it resets to it's default properties, and then resets in the design window too.
I'm I missing something here? Do I need a special attribute to tell properties to persist, and shouldn't they persist anyway? Otherwise all these design time properties I've added are rather pointless.
Cheers,
Dave
Dave Kerr
focus_business@hotmail.com
www.focus.esmartweb.com
|
|
|
|
|
I did some work with this a while back. I remember it got tricky depending on the type of your properties.
There is a DesignerSerializationVisibilityAtttribute you can apply to change the default designer serialization behavior. If the property is a collection, you may need
[DesignerSerialzationVisibility(DesignerSerialization.Content)] and a property get that returns the collection.
If you property values are instances of some custom type, you may need to use the DesignerSerializerAttribute .
More detail about the type of the property might be useful.
Burt Harris
|
|
|
|
|
I used the following code to download the source of an HTML page:
<br />
...<br />
try<br />
{<br />
HttpWebRequest _request = (HttpWebRequest)WebRequest.Create(_url);<br />
<br />
if (_useProxy)<br />
{<br />
WebProxy _proxy = new WebProxy(_proxyHost + ":" + _proxyPort.ToString());<br />
_request.Proxy = _proxy;<br />
}<br />
<br />
HttpWebResponse _response = (HttpWebResponse)_request.GetResponse();<br />
<br />
if (_response.StatusCode == HttpStatusCode.OK)<br />
{<br />
Stream _stream = _response.GetResponseStream();<br />
StreamReader _streamReader = new StreamReader(_stream, Encoding.UTF8);<br />
MessageBox.Show(_streamReader.ReadToEnd().Trim());<br />
}<br />
catch (WebException we)<br />
{<br />
}<br />
catch (Exception e)<br />
{<br />
}<br />
...<br />
My question is, what if the page I need to access requires authentication. In other words, when browsing normally, with a web browser client, a dialog pops up asking for my username and password. I have the access information, but I want the preceding code to be able to send that authentication information along and get the code without any user intervention.
Any ideas?
|
|
|
|
|